Need Tkinter help - Label with image

Matthew Dixon Cowles matt at
Sat Jan 12 16:37:16 EST 2002

On Sat, 12 Jan 2002 12:35:28 -0800, Daryl P McDaniel
<python at> wrote:

Dear Daryl,



>I am having a problem with Tkinter that I don't understand.  I have
>consulted "Python and Tkinter Programming", by John Grayson, and "An
>Introduction to Tkinter", by Fredrik Lundh, without finding an

>Basically, I can't get a Label to display an image if both the
>PhotoImage and Label calls are contained within the same function.  I
>can make my application work, but don't want to ship it until I
>understand what is going on.

>    When both the PhotoImage and Label function calls are made in the
>    same function, the Label is blank, but at the correct size.  If
>    the PhotoImage and Label function calls are not in the same
>    function, the Label displays the image properly.

It's an odd feature feature in Tkinter. You need to keep an extra
reference to your image around to prevent it from being garbage-
collected. In your examples that work, you do that by making it a
global. If your Tkinter widgets are wrapped up in Python objects,
another useful way is to assign the image to an attribute of the
object. Something like:



More information about the Python-list mailing list