我意识到有很多examples如何通过调用root.destroy()函数来正确关闭Tkinter GUI。他们使用我的设置,除了我已经确定包括tkinter.intvar类型的变量导致gui进程在我关闭窗口后仍然存在。这是一个有效的例子:
import mtTkinter as Tkinter #special threadsafe version of Tkinter module, required for message windows. You can use regular Tkinter if needed
root = Tkinter.Tk()
root.wm_title("KillmePlz")
nexusvar = Tkinter.IntVar()
def ClosebyX():
root.destroy()
closebutton = Tkinter.Button(root,text='Quit',command=ClosebyX)
closebutton.pack()
root.protocol('WM_DELETE_WINDOW', ClosebyX)
root.mainloop()
在我的机器上,如果我删除" nexusvar",Tkinter.IntVar的创建,当我关闭GUI时,该过程也会停止。如果如上所示包含此变量,我会在gui关闭后看到进程停留。我认为mtTkinter没有任何区别。
有谁知道为什么会这样?
Windows 7 64位,Python 2.7.12
更新9/20/16: mtTkinter是这个问题的根源。以下解决方案适用于常规Tkinter模块。要使用mtTkinter解决此问题,请参阅以下post
答案 0 :(得分:1)
nexusvar
不是root
的孩子,因此当您销毁root
时,它也不知道要销毁nexusvar
- 这两件事是分开的。您可以通过向构造函数提供IntVar
来将root
设置为root
作为父级。 nexusvar
在root
死亡时应该能够自我毁灭。