[英]Running Python3 program using tkinter in the console (command line)
My Python3 program contains Tkinter . 我的Python3程序包含Tkinter 。 It runs properly in Idle3 and it runs properly in the LXTerminal . 它运行正常在IDLE3并在LXTerminal正常运行。
It will not run in the console. 它不会在控制台中运行。 In the console (command-line) I get the following error message: 在控制台(命令行)中,我收到以下错误消息:
File "/usr/lib/Python2.7/lib-tk/Tkinter.PY",line 1712,
in_init_self.tk=tkinter.create(screenName,baseName,className,interactive,wantobjects,useTk,sync,use)_tkinter.TCLError:
no display name and no $DISPLAY envronment variable.
I am using the latest NOOBS installation for Raspbian . 我正在为Raspbian使用最新的NOOBS安装。
This is the code I am running - 这是我正在运行的代码-
from Tkinter import *
root = Tk()
canvas = Canvas(root, width=300, height=200)
canvas.pack()
root.mainloop()
it's because the terminal you're trying to run your program in does not have access to an X instance, whereas it tries to access it. 这是因为您要在其中运行程序的终端无权访问X实例,而试图访问它。
I'm not sure and can't tell whether this is because TkInter assumes it needs X on import or because your code is explicitly creating a graphical object whereas you're running it in the consel. 我不确定,也无法确定这是因为TkInter假定它在导入时需要X,还是因为您的代码正在显式创建图形对象,而您却在consel中运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.