SV: Quit-command not quiting

Gabriel Genellina gagsl-py2 at
Sat Mar 8 23:14:18 CET 2008

En Fri, 07 Mar 2008 13:56:45 -0200, K Viltersten <tmp1 at>  

>>> The window itself vanishes if i click the
>>> cross in the upper-right corner but pressing
>>> the quit-button only makes it "pressed".
>>> Then, the program freezes.
>> How did you run it? From inside IDLE? IDLE itself is written
>> using Tk, and  I think that your mainloop interferes with the
>> one inside it. If you run your program from the command line
>> it should work fine.
> I press F5 while in the editor window. Is there a way to run the
> program without going to the console window?
> Perhaps i'm just making things unneccesarily complicated
> and Python IS supposed to be run from console window?

No, use IDLE if you prefer, or any other editor/IDE. But in your case  
there is an unfortunate coupling between IDLE and your script. Fix: change  
the quit method as suggested in this thread:

     def quit(self):

This is OK if used on the top level widget on the application (your Demo  
class, for instance). A more general solution:

     def quit(self):
         parent = self
         while parent.winfo_class() != 'Tk':
             if parent.master is None:
             parent = parent.master


This appears to work fine. But the loop, as written, could exit without  
calling destroy() on anything; perhaps some other people knowing better  
how Tkinter and Tk work could improve it or confirm it's fine as it is.

Gabriel Genellina

More information about the Python-list mailing list