0

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()
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()

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

Community
  • 1
  • 1
willpower2727
  • 769
  • 2
  • 8
  • 23

1 Answers1

1

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.

Delioth
  • 1,564
  • 10
  • 16
  • I tried nexusvar = Tkinter.IntVar(master=root) and I still observe the same issue. Is that what you meant when you say make root the parent? – willpower2727 Sep 19 '16 at 17:59
  • I can confirm the issue persists whether in IDLE shell or from an executable (py2exe) – willpower2727 Sep 19 '16 at 18:46
  • It looks my use of mtTkinter module is the culprit. When I apply your solution with the regular Tkinter module there are no issues. mtTkinter needs to address this – willpower2727 Sep 19 '16 at 18:48