Ask coding questions

← Back to all posts
What is this error and how can you fix it?
WilliamXing

Traceback (most recent call last):
File "main.py", line 15, in <module>
background = PhotoImage(file='The word hi.jpeg')
File "/usr/lib/python3.8/tkinter/init.py", line 4061, in init
Image.init(self, 'photo', name, cnf, master, **kw)
File "/usr/lib/python3.8/tkinter/init.py", line 4006, in init
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "The word hi.jpeg"

Answered by 19wintersp [earned 5 cycles]
View Answer
Voters
WilliamXing
Comments
hotnewtop
19wintersp

I believe this error suggests a corrupted or invalid image.

You might be able to fix this by using PIL.

19wintersp

Update: using PIL's ImageTk works correctly for me; replace line 16 with:

and add this to the top:

WilliamXing
mattman101

if you share me the code i might be able to find the mistake