[Tkinter-discuss] Doing things on Tkinter termination
klappnase at web.de
Tue Jan 26 11:34:03 CET 2010
On Tue, 26 Jan 2010 10:11:31 +0100
Geoff Bache <geoff.bache at gmail.com> 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?
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!!!"
More information about the Tkinter-discuss