Tkinter intvar 导致进程继续存在

Tkinter intvar causing process to live on

我知道有很多 examples 如何通过调用 root.destroy() 函数正确关闭 Tkinter GUI。它们与我的设置一起工作,除了我确定包含类型 tkinter.intvar 的变量会导致 gui 进程继续运行,即使在我关闭 window 之后也是如此。这是一个工作示例:

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

2016 年 9 月 20 日更新: mtTkinter 是这个问题的根源。下面的解决方案适用于常规 Tkinter 模块使用。要使用 mtTkinter 解决此问题,请参阅以下 post

nexusvar 不是 root 的子节点,所以当你销毁 root 时,它也不知道要销毁 nexusvar - 这两件事是分离。您可以通过向构造函数提供 root 来将 IntVar 设置为将 root 作为父级。 nexusvar 应该能够在 root 死亡时自我毁灭。