Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't recognize data in image file "image1.png" – Unable to load png

I’m trying to make an app using Python and Tkinter but I’m not able to load an image, or png to be specific. Instead, I’m getting this long error:

 File "C:\Users\username\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4038, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "image1.png".

Can someone help me fix this? Here are the lines of code that might be causing the error:

cycle1IMG = tk.PhotoImage(file="image1.png")

def openNewWindow1():
    newWindow = Toplevel(master)
    newWindow.title("🚲Cycle 1")
    newWindow.geometry("750x500")
    Label(newWindow, text="Cycle 1", image= cycle1IMG).pack()

cycle1 =tk.Button(
    root,
    text="🚲Cycle 1",
    command=openNewWindow1
    
)
cycle1.place(x=500,y=300)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Based on a comment to the question, it appears that you took a .webp file and just renamed it to .png. This doesn’t change the internal contents of the file, which is why tkinter reported the error: you told it to open a .png file but the contents of the file isn’t in the png format.

Tkinter doesn’t support webp. You’ll have to use some other library to read the file and convert it to a format supported by tkinter (eg: pillow)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading