使用tkinter画图,例如运行以下代码:
import os
from nltk import Tree
from nltk.draw.util import CanvasFrame
from nltk.draw import TreeWidget
cf = CanvasFrame()
t = Tree.fromstring('(S (NP this tree) (VP (V is) (AdjP pretty)))')
tc = TreeWidget(cf.canvas(), t)
cf.add_widget(tc, 10, 10) # (10,10) offsets
cf.print_to_file('tree.ps')
cf.destroy()
在没有图形化界面的的服务器上,会显示以下错误
_tkinter.TclError: no display name and no $DISPLAY environment variable
拉到本地运行,没有任何错误,生成ps图片.