Cleaning Up an Application When the Window is Closed

Mike Driscoll kyosohma at gmail.com
Sun Feb 17 22:08:06 EST 2008


On Feb 17, 8:31 pm, "W. Watson" <wolf_tra... at invalid.com> wrote:
> Suppose I write some Win XP application using the Tkinter GUI, and do not
> provide a mechanism to exit other than the user clicking on the X in the
> upper right corner of a window. Is there a mechanism that will allow me to
> put up an save-dialog to give the user the option to save his present state
> of data?
> --
>                           Wayne Watson (Nevada City, CA)
>
>                         Web Page: <speckledwithStars.net>

You just need to catch the close event, which appears to be
"WM_DELETE_WINDOW" in Tkinter. The following article details its usage
near the bottom of the page under the heading "Protocols":

http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm

It actually mentions your problem specifically. I've never done it as
I usually use wxPython.

HTH

Mike



More information about the Python-list mailing list