TKinter-destroying a window

Fredrik Lundh effbot at telia.com
Tue Apr 18 10:39:14 EDT 2000


gregholmes at my-deja.com wrote:
> Sorry, I'm reading TFM but haven't figured this
> out yet. If I am done with a secondary (or
> tertiary, or whatever) window (in TKinter), can I
> just destroy the window or do I need to get rid
> of any class instantiation that is
> attached/associated to it? i.e.
>
> ....
> theWindow=Toplevel()
> solveThis=SolveThis(theWindow)
> ....
> theWindow.destroy()
>
> Will the class instantiation and its variables
> and everything still be laying around?

not everything -- destroy releases all the Tk specific
stuff, but the proxy object hangs around until you've
removed all references to it.

(since Python objects don't know who's referring to
them, they cannot destroy all references by them-
selves).

in your case, assuming that "theWindow" is a global
variable, you can use:

    del theWindow

or

    theWindow = None

to get rid of it (assuming SolveThis doesn't create
a circual reference, that is).

if the code is local scope (inside a function or a
method), the variable will be deleted by Python
when you leave that scope.

</F>





More information about the Python-list mailing list