TclError: Could not recognize data in image file "background.png"

I recently switched to Python 2.7 (from 3.4) and am having a hard time reading a .png file using the Tikinter Photoimage class. I say:

background = "background.png"
photo = tk.PhotoImage(file=background)

      

But I am getting this error:

Traceback (most recent call last):
  File "main.py", line 36, in <module>
    photo = tk.PhotoImage(file=background)
  File "c:\Python27\lib\lib-tk\Tkinter.py", line 3323, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "c:\Python27\lib\lib-tk\Tkinter.py", line 3279, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "background.png"

      

+3


source to share


1 answer


img = ImageTk.PhotoImage(Image.open(background))

      



+2


source







All Articles