我创建了一个直接从根窗口继承的简单类,它可以在Mac机器上完美地工作。然而,当我试图在我自己的基于Ubuntu的机器上运行它时,它崩溃了,出现了以下错误。是什么原因造成的?你知道吗
Traceback (most recent call last):
File "/home/estilen/Dropbox/Python/email_viewer/dialog.py", line 15, in <module>
Dialog('This is definitely working')
File "/home/estilen/Dropbox/Python/email_viewer/dialog.py", line 7, in __init__
tk.Tk.__init__(self, dialog_message)
File "/usr/lib/python3.5/tkinter/__init__.py", line 1871, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "This is definitely working"
代码:
import tkinter as tk
class Dialog(tk.Tk):
def __init__(self, dialog_message):
tk.Tk.__init__(self, dialog_message)
self.geometry('400x100')
label = tk.Label(self, text=dialog_message)
label.pack(anchor='center', side='top', pady=10)
self.mainloop()
if __name__ == '__main__':
Dialog('This is definitely working')
我觉得这不对劲。Tk构造函数的第一个位置参数是^{} 。如果您不想在名为“This is finally working”的显示器上显示窗口,则不要提供该参数。你知道吗
。。。或者,更习惯地说
相关问题 更多 >
编程相关推荐