Tkinter: Why won't it work?

Brian Kelley bkelley at wi.mit.edu
Wed Mar 27 11:27:35 EST 2002


A.Newby wrote:

> Hi.
> 
> Below is an example exercise from "An Introduction to Tkinter" by Fredrik 
> Lundh. It simply creates a box with a quit button in it. Problem is, 
> everytime I click Quit, the program freezes. 
> 
> Is this a rare but well known bug with Tkinter, Python 2.2, or Windows 98? 
> Or is more probable that it's cuz my system is screwed?
> 
> 


Does this problem exist when you hit the "QUIT" button or the "X" in the 
upper left corner of the window?

This code seems to work fine in Python 2.2 windows 2000 but in chapter 7 
of Introduction to Tkinter:

===================
Note that even [though] you don't register an handler for 
WM_DELETE_WINDOW on a toplevel window, the window itself will be 
destroyed as usual (in a controlled fashion, unlike X). However, as of 
Python 1.5.2, Tkinter will not destroy the corresponding widget instance 
hierarchy, so it is a good idea to always register a handler yourself:

top = Toplevel(...)

     # make sure widget instances are deleted
     top.protocol("WM_DELETE_WINDOW", top.destroy)

Future versions of Tkinter will most likely do this by default.
====================


Here if you are ultra paranoid, you might want to alter the protocol of 
your root window as above.  This is also handy for popping up a message 
box asking something like "Are you sure" for conformation.

-Brian




More information about the Python-list mailing list