__del__() in a Tkinter app

Richard richard at NOstarfighterSPAM.freeuk.com
Sat Dec 16 13:12:20 EST 2000


"Fredrik Lundh" <fredrik at effbot.org> wrote in message
news:ZKJ_5.110$u17.27823 at newsb.telia.net...
> "Richard" wrote:
> > I have tried adding a __del__() method to a Tkinter application so it
can
> > remove temporary files when the program exits.
>
> Don't ever do things like that in a __del__ method.   Python isn't
> C++, and doesn't make any guarantees that __del__ methods will
> ever be called.
>
> To properly shut down a Tkinter application, bind the "<Destroy>"
> event on the root/toplevel window.
>
> You can also overload the destroy method:
>
>     class myGUI(Tk):
>
>         def __init__(self, ...):
>             Tk.__init__(self)
>             # not really needed in 2.0 and later, but it doesn't hurt
>             self.protocol("WM_DELETE_WINDOW", self.destroy)
>
>         def destroy(self):
>             Tk.destroy(self)
>             ... handle shutdown
>
> </F>
>
>

Thanks Fredrik, I've used your suggestion to handle shutdown in my app,
without using a __del__() method.

regards,
Richard






More information about the Python-list mailing list