PNG images in PhotoImage labels

moonlite56 at moonlite56 at
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()

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)


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

Traceback (most recent call last):
  File "", line 9, in ?
    iKuti = PhotoImage(file = "gameboy.png")
  File "/usr/lib/python2.0/lib-tk/", line 2974, in __init__
    apply(Image.__init__, (self, 'photo', name, cnf, master), kw)
  File "/usr/lib/python2.0/lib-tk/", line 2930, in __init__'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