[Tkinter-discuss] Possibly n00bish question about ImageTk

mkieverpy at tlink.de mkieverpy at tlink.de
Thu Jun 28 11:29:11 CEST 2007


Hi Alan,

in your function 'moo' 'pi' is a local variable which
gets garbage collected when the function returns.
Thus your image goes to gc nirvana.
Making 'pi' global like this

def moo(master):
    global pi
    img = Image.open('plotfig.png')
    f = Tkinter.Frame(master, width=800, height=600)
    pi = ImageTk.PhotoImage(img)
    t = Tkinter.Label(f, image=pi)
    f.pack()
    t.place(x=0, y=0, width=800, height=600)
    t.pack()

should do the trick.
This is a guess as I am not using Image and ImageTk.
But I had the same problem with Tix.PhotoImage. So I guess this is it.

BTW you use 'place' and 'pack' for the label. As I understood
your supposed to use exactly ONE geometry handler for a gui element in tk.

Hope this helps,

Matthias Kievernagel
(mkiever/at/web/dot/de)


More information about the Tkinter-discuss mailing list