How to terminate a TkinterApp correctly?

Michael Peuser mpeuser at web.de
Sat Aug 16 15:44:37 EDT 2003


"Gregor Lingl" <glingl at aon.at> schrieb im Newsbeitrag
news:3F3E84DA.8040905 at aon.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
procedure...

> 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
program!!


See this example:
---------------------------
from Tkinter import *

def killingAction():
    l.master.destroy()

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


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

l.master.protocol("WM_DELETE_WINDOW",kidding)


mainloop()
print "here we are- ready for whatever we want"
-----------------------







More information about the Python-list mailing list