[Tkinter-discuss] WM_DELETE_WINDOW

Stanley Sokolow overbyte at earthlink.net
Sun Mar 16 01:51:03 CET 2008

Here's a tip to help new Tkinter programmers avoid the trouble I had because
of an error in Grayson's book "Python and Tkinter Programming" published by
Manning.   On page 309 the protocol methods are briefly explained, with an
self.root.protocol(WM_DELETE_WINDOW, self.cleanup)

This does not work.   There is no error correction in the errata page on the
Manning site for the book.  I finally figured out that WM_DELETE_WINDOW is
not a pre-defined constant like TOP, but rather should be a string in
quotes.   The correct way to invoke the protocol to intercept toplevel
window closing is:
self.root.protocol("WM_DELETE_WINDOW", self.cleanup)

I wrote to Manning to have them add this to their errata, but just in case
they don't do it, I wanted to post this correction note here for others to
View this message in context: http://www.nabble.com/WM_DELETE_WINDOW-tp16074408p16074408.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.

More information about the Tkinter-discuss mailing list