How to terminate a TkinterApp correctly?

Michael Peuser mpeuser at web.de
Sat Aug 16 14:35:19 EDT 2003


"John Roth" <newsgroups at jhrothjr.com> schrieb im Newsbeitrag
news:vjsslisoeitsc9 at news.supernews.com...
>
> "Michael Peuser" <mpeuser at web.de> wrote in message
> news:bhlmgq$dqk$02$1 at news.t-online.com...
> >
> > ----- Original Message -----
> > From: "Gregor Lingl" <glingl at aon.at>
> > Newsgroups: comp.lang.python
> > Sent: Saturday, August 16, 2003 3:53 PM
> > Subject: Re: How to terminate a TkinterApp correctly?
> >
> > ....
> >
> > > Thanks for your remarks and your example. The
> > > following solution finally did it:
> > >
> > > def exit():
> > >      global done
> > >      done = True # so the animation will terminate, but
> > >                  # not immediately! The actual pass through
> > >                  # the loop has to be finished.
> > >      print "done!"
> > >      import sys
> > >      # after_idle seems to be crucial! Waits for terminating
> > >      # the loop (which is in a callback function)
> > >      cv.after_idle(sys.exit, (0,))
> >
> >
> > Why don't you just return? The mainloop can handle everything!?
>
> Unfortunately, the combination of Windows 9x (including Me)
> and Python 2.1 can't handle everything. It may also be broken
> in 2.2 and later, but I quit trying after reaching my frustration
> limit. If you exit with an exception, something doesn't clean up
> properly, and you break the DOS box and eventually Windows
> itself when you try to shut down.
>
> This problem doesn't exist in the Windows 2K (including XP)
> code base, or other variants.
>
> 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. This is where you set "done=1" for...
The after_idle is confusing and probably not what you want. I have the
impression that there is still some misunderstanding.

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! - to just call
sys.exit() !!!

Kindly Michasel P


> John Roth
>
>
>






More information about the Python-list mailing list