Quitting a Tkinter application with confirmation
Fredrik Lundh
fredrik at pythonware.com
Wed Nov 16 14:48:25 EST 2005
Peter Kleiweg wrote:
> I want the program to behave identical if the 'close' button of
> the application window is clicked. I tried the code below,
> using a class derived from Tk that redefines the destroy
> method. That seems to work. At least on Linux.
>
> My questions:
>
> Is this the correct and save way to do this? Will it work on any
> operating system? Shouldn't I do some event capturing instead?
the right way to do this is to implement a WM_DELETE_WINDOW
protocol handler:
http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm#protocols
in your case, adding
root.protocol("WM_DELETE_WINDOW", root.destroy)
to the right place should be enough.
> (Capture the SIGTERM or SIGQUIT, sent by the Window manager to
> the application.)
that's signals, not events, and should not be needed. (afaik, a properly written
X Window application should shut down by itself, in response to DestroyWindow
requests from the window manager. if the window manager has to use explicit
kill signals to get rid of an application, something's wrong).
</F>
More information about the Python-list
mailing list