Hi Geoff,

On Tue, 26 Jan 2010 10:11:31 +0100
Geoff Bache <[email protected]> wrote:

> Hi all,
> 
> How would you add some code that is called when the application is
> terminated, that is independent of whether it was closed via the
> window manager or via some programmatic call within the application,
> such as a call from a "quit" button?

    root.protocol("WM_DELETE_WINDOW", your_quit_method)

This way, your_quit_method() will be called when the window manager 
closes the window through the window's "close" button (i.e. usually the
cross in the upper right corner) or through Alt-F4 or so. In most cases
it is a good idea to define a "WM_DELETE_WINDOW" callback even if it is
only root.quit() to make sure you have control over what happens when
the user clicks the "close" button.
Of course, if you have some code that should be called after the window
is closed, you can also simply put it below the mainloop().

> 
> I tried binding to the "destroy" event like this:
> 
> from Tkinter import *
> 
> def destroyed(*args):
>     print "AAARRGGGH!!!"
> 

:)))

Regards

Michael
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to