4

I've switched over to Python 2.7 (from 3.4) recently, and I'm having trouble reading a .png file with Tkinter Photoimage class. I say:

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

But I get 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"
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
user4261180
  • 151
  • 2
  • 3
  • 11
  • 1
    Does this answer your question? [Tkinter error: Couldn't recognize data in image file](https://stackoverflow.com/questions/47357090/tkinter-error-couldnt-recognize-data-in-image-file) – Karl Knechtel Feb 22 '23 at 21:26

1 Answers1

0
img = ImageTk.PhotoImage(Image.open(background))
the_prole
  • 8,275
  • 16
  • 78
  • 163