[Tkinter-discuss] main window closing when dialogs are open
Bencsik Roland
roland.bencsik at ludensis.hu
Mon Oct 16 12:42:01 CEST 2006
Hello Tkinter list,
Could you please help me out how can I make my program exit cleanly if I
pop up some dialog boxes?
My sample code is below.
When I execute python WindowClosingTest.py, open the dialog by pressing
the Info button and close the program by clicking on the close button
(X) of the main window than the dialog box and the main window
disappears but the python interpreter does not exits.
If I close the dialog before pressing the window closing button then it
works fine.
I use Linux (Fedora Core 5), KDE (3.5.4), Python with shipped Tkinter
(2.4.3)
Thanks in advance,
Roland
# File: WindowClosingTest.py
from Tkinter import Tk
from Tkinter import Button
from Tkconstants import LEFT
import tkMessageBox
class Gui:
def __init__(self, owner):
self.owner = owner
Button(owner, text="Info", command=self.info).pack(side=LEFT)
Button(owner, text="Quit", command=self.quit).pack(side=LEFT)
def quit(self):
print "quit starts"
print "cleaning up things..."
self.owner.destroy()
print "quit ends"
def info(self):
tkMessageBox.showinfo(
"title",
"message",
parent=self.owner
)
root = Tk()
gui = Gui(root)
root.protocol("WM_DELETE_WINDOW", gui.quit)
root.mainloop()
print "after mainloop"
# EOF
More information about the Tkinter-discuss
mailing list