How to terminate a TkinterApp correctly?

Gregor Lingl glingl at aon.at
Sat Aug 16 15:34:44 EDT 2003


Michael Peuser schrieb:

> "John Roth" <newsgroups at jhrothjr.com> schrieb im Newsbeitrag
...

>>>Why don't you just return? The mainloop can handle everything!?
>>
>>Unfortunately, 

...
>>I don't know that it's ever been solved, but considering that
>>Windows 9x is gradually going away, it's also not a real hot
>>priority.
> 
> 
> 
> This was not my point I think....  I was not referring to tk/system mainloop
> but to your own loop you mentioned.

The above answer was not mine, so there is samething a bit mangled ...

  This is where you set "done=1" for...
> The after_idle is confusing and probably not what you want. 

But it worked!

I have the
> impression that there is still some misunderstanding.

Maybe!

> It is absolutly fine to intercept the user click to the close box - there is
> no magic it and - as to my example - you can do what you want for hours
> after. Note: the "closing" process is stopped, when you use this WM-....
> trick. (Because I was not *quite* sure about the internal states, I also
> recommende to use WM_SAVE_YOURSELF  instead).
> 
> But I think it is not worth all the work - and still unsafe! - 

WHY?

to just call
> sys.exit() !!!

So I found another working solution to my problem:
I put the code for the go-function, which is the command of a goButton
in a try:- except: clause.

def go():
     global done
     try:
         resetGame()
         goButton["state"] = Tk.DISABLED
         while fehler < MAXFEHLER  and not done:
             for huhn in huehner:
                 huhn.move()
             cv.update()
         done = True
         goButton["state"] = Tk.NORMAL
     except:
         pass

This catches the TclError and everything terminates regularly
Regards, Gregor

> Kindly Michasel P
> 
> 
> 
>>John Roth
>>
>>
>>
> 
> 
> 





More information about the Python-list mailing list