How to terminate a TkinterApp correctly?

Michael Peuser mpeuser at web.de
Sat Aug 16 12:35:13 EDT 2003


----- 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!?
Example:
     def exit(self):
        self.done=1
        return

(If you can put it into an appropriate class ....)

>
> cv.master.protocol("WM_DELETE_WINDOW", exit)
>
> if not usingIDLE:
>      root.mainloop()
>
> Regards, Gregor
>






More information about the Python-list mailing list