willpower2727 willpower2727 - 1 month ago 5x
Python Question

Tkinter intvar causing process to live on

I realize there are many examples of how to properly close a Tkinter GUI by calling the root.destroy() function. They work with my setup except I've determined that including a variable of type tkinter.intvar causes the gui process to live on even after I close the window. Here's a working example:

import mtTkinter as Tkinter #special threadsafe version of Tkinter module, required for message windows. You can use regular Tkinter if needed

root = Tkinter.Tk()

nexusvar = Tkinter.IntVar()

def ClosebyX():

closebutton = Tkinter.Button(root,text='Quit',command=ClosebyX)
root.protocol('WM_DELETE_WINDOW', ClosebyX)

On my machine if I remove the creation of "nexusvar", the Tkinter.IntVar, when I close the GUI the process also stops. If this variable is included as shown above, I see the process linger after the gui is closed. I don't think mtTkinter makes any difference.

Does anyone know why this might be happening?

Windows 7 64 bit, Python 2.7.12

UPDATE 9/20/16:
mtTkinter is the source of this problem. The solution below is for regular Tkinter module use. For solving this problem using mtTkinter see the following post


nexusvar isn't a child of root, so when you destroy root it doesn't know to destroy nexusvar as well - the two things are separate. You can set an IntVar to have root as a parent by supplying root to the constructor. nexusvar should then be able to destroy itself when root dies.