How to terminate a TkinterApp correctly?
Michael Peuser
mpeuser at web.de
Sat Aug 16 06:24:00 EDT 2003
"Gregor Lingl" <glingl at aon.at> schrieb im Newsbeitrag
news:3F3DFCF4.5020109 at aon.at...
> I'm working on a windows machine
>
> I've written a Tkinter-app (sort of game) which
> consists mainly of an animation which is driven
> by a while True: ... loop.
>
[....]
> Only if this loop is terminated by some other means
> - e.g. game over - before closing the window no
> error message is displayed.
>
Correct
> How, i.e. by what sort of event handler or error handler
> can I avoid this annoying behaviour of my program?
>
You can bind <Destroy> and act accordimngly, or intercept the action
altogether.
Example:
-----------------------------
from Tkinter import *
def killingAction(ev):
print "Destroyed"
def kidding():
print "not killing"
l.config(text="just kidding")
l.master.protocol("WM_DELETE_WINDOW",original)
l=Label(text="Kill me!")
l.pack()
l.bind("<Destroy>",killingAction)
original= l.master.protocol("WM_DELETE_WINDOW",None)
l.master.protocol("WM_DELETE_WINDOW",kidding)
l.master.destroy=lambda: 0
mainloop()
--------------------------------------------
Kindly
Michael P
> Regards, Gregor
>
More information about the Python-list
mailing list