SV: SV: Quit-command not quiting

K Viltersten tmp1 at
Sun Mar 9 01:55:50 CET 2008

"Gabriel Genellina" <gagsl-py2 at> skrev i meddelandet 
news:mailman.1750.1205017517.9267.python-list at
> En Fri, 07 Mar 2008 13:56:45 -0200, K Viltersten <tmp1 at> 
> escribi�:
>>>> 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):
>         self.master.destroy()
> 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:
>                 break;
>             parent = parent.master
>         else:
>             parent.destroy()
> (from 
> )
> 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.

Thank you. I'll try that tomorrow.

Konrad Viltersten
sleep    - a substitute for coffee for the poor
ambition - lack of sense to be lazy

More information about the Python-list mailing list