Tkinter.PhotoImage question
Dr. Kent L. Miller
kmiller at csis.american.edu
Sun Oct 8 09:55:02 EDT 2000
I would like to display image files onto labels and canvasses. I noticed
however, that if I call PhotoImage from within a function, no image will
appear. When I run the following code, a photo appears on the label but
not the canvas, even though the lines and bitmap do appear. Is this a
Tkinter bug? Is there a workaround?
import Tkinter
def body(master):
f = Tkinter.Frame(root)
f.pack()
c = Tkinter.Canvas(f)
c.pack()
photo2 = Tkinter.PhotoImage(file="lena.gif")
c.create_line(0,150,150,0)
c.create_image(10,10,anchor=Tkinter.NW, image=photo2)
c.create_line(0,0,150,150)
c.create_bitmap(100,100,bitmap="info",foreground="gold")
l = Tkinter.Label(f, image=photo)
l.pack()
root = Tkinter.Tk()
photo = Tkinter.PhotoImage(file="lena.gif")
body(root)
root.mainloop()
Sincerely Yours,
Kent
More information about the Python-list
mailing list