PNG images in PhotoImage labels

moonlite56 at yahoo.com moonlite56 at yahoo.com
Tue Aug 7 05:12:14 CEST 2001


I am learning Python this summer, and kind of ran into a rut when I 
tried to display .png images in a simple label test. This is what I 
have so far:


from Tkinter import *

top = Tk()
top.title("Kuti")
top.geometry("200x100")

iKuti = PhotoImage(file = "gameboy.png")
lHello = Label(top, image = iKuti)
lHello.grid(row = 1, col = 1, sticky = W)
bQuit = Button(top, text="Quit", command = top.quit)
bQuit.grid(row = 1, col = 2, sticky = E)

top.mainloop()


This works with gameboy.gif, but gameboy.png displays an error:


Traceback (most recent call last):
  File "tkinter.py", line 9, in ?
    iKuti = PhotoImage(file = "gameboy.png")
  File "/usr/lib/python2.0/lib-tk/Tkinter.py", line 2974, in __init__
    apply(Image.__init__, (self, 'photo', name, cnf, master), kw)
  File "/usr/lib/python2.0/lib-tk/Tkinter.py", line 2930, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't recognize data in image file "gameboy.png"


How do I get this to work with PNG images?






More information about the Python-list mailing list