How to terminate a TkinterApp correctly?

Michael Peuser mpeuser at
Sat Aug 16 21:44:37 CEST 2003

"Gregor Lingl" <glingl at> schrieb im Newsbeitrag
news:3F3E84DA.8040905 at
> Michael Peuser schrieb:


> > Why don't you just return? The mainloop can handle everything!?
> > Example:
> >      def exit(self):
> >         self.done=1
> >         return
> >
> Here I apparently don't understand something fundamental:
> what is the effect of a return statement as the last statement
> of a function?

Nothing, just an indicator to make clear that this is the end of the

> Moreover: If I put this into the cv.master.protocol ... I cannot
> close the application at all. (Because the original is not restored.
> And I don't want to need a second mouseclick as in your first example.)

This is a misunderstanding. Closing your application has nothing to do with
closing some window and even less with where a stupid user clicks on ;-)

You can destroy a widget with "destroy"; when the root widget is destroyed
then the Tkinter mainloop terminats by convention. Nothing to do with your

See this example:
from Tkinter import *

def killingAction():

def kidding():
        l.config(text="just kidding")

l=Button(text="Kill me!",command=killingAction)


print "here we are- ready for whatever we want"

More information about the Python-list mailing list