Tkinter wart: bug or feature?

David Eppstein eppstein at ics.uci.edu
Fri Nov 15 16:36:32 EST 2002


In article <3dd563db.9499247 at nntp.ix.netcom.com>,
 support @ internetdiscovery.com (Mike Clarkson) wrote:

> This started out as a bug report by Peter Deutsch about disappearing
> bitmap images:
...
>     image1 = Tkinter.Image('photo', file=file)
>     lbl = Tkinter.Label(win.window, image=image1)
>     lbl.pack(expand=1, fill=Tix.BOTH)
> 
> The image will not show up if the variable image1 is not
> declared global. I
...
> >When the BitmapImage object is no longer referenced, it is
> >finalized; finalization causes "image delete" to be invoked.
> 
> >Tcl does not keep a reference to the image object; if you
> >don't yourself, nobody does. In turn, the image object goes
> >away right after being created.
> 
> And sure enough, the Tkinter.Image class has a __del__ method
> that does an image delete on the image, so when the procedure
> finishes it deletes the image image1 even though Label wants to make
> use of it.

So, just so I'm clear about this, the workaround is to add image = None
to your procedure, before it returns?

I have some vague memory of hitting something like this (at least, 
tkInter images mysteriously failing to work) when I first tried to learn 
Python, which none of the MacPython experts I asked about could figure 
out, and which permanently turned me off from using tkInter.
So consider this to be corroboration that, if it's not an outright bug, 
it's a serious design misfeature.

-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list