[Tutor] simple graphical labels with Tkinter

Bryce Embry bryce@bembry.org
Mon, 13 May 2002 10:18:31 -0500


Use PhotoImage to get the picture, then point the "image=" option to the 
PhotoImage object.

Here's a sample script:

from Tkinter import *
root = Tk()

pic = PhotoImage(file="k:\\Python\\tkinter\\test.gif")
lbl = Label(root, image = pic)
lbl.grid()

root.mainloop()  #omit if running in IDLE


the PhotoImage needs the complete path only if the image is not in the 
current directory.  If you are running the GUI from inside IDLE, this can 
be an issue for getting the path right.

Also, according to Grayson's book, Tkinter is limited to gif, pgm, and ppm 
files.  I think there is a way to extend it to accept png / jpg, but I 
don't know how.

Hope this helps.

Bryce


At 09:42 AM 5/13/2002, you wrote:
>Hi everyone,
>
>If I've got a GIF file, how can I place that graphic into a Tkinter
>Label widget?
>
>-Tim
>
>--
>Tim Wilson      |   Visit Sibley online:   | Check out:
>Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
>W. St. Paul, MN |                          | http://slashdot.org
>wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

--------------------------------------------------------------------------------------------
"Lord, you establish peace for us.
All that we have accomplished
you have done for us" -- Isaiah 26:12