close

[Solved] Tkinter error: Couldn’t recognize data in image file

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Tkinter error: Couldn’t recognize data in image file in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Tkinter error: Couldn’t recognize data in image file Error Occurs?

Today I get the following error Tkinter error: Couldn’t recognize data in image file in python.

How To Solve Tkinter error: Couldn’t recognize data in image file Error ?

  1. How To Solve Tkinter error: Couldn't recognize data in image file Error ?

    To Solve Tkinter error: Couldn't recognize data in image file Error I was getting the same issue. I have windows and Python 3.6. So I found two solutions for this either you use/convert to .png image (with the same function you have used):

  2. Tkinter error: Couldn't recognize data in image file

    To Solve Tkinter error: Couldn't recognize data in image file Error I was getting the same issue. I have windows and Python 3.6. So I found two solutions for this either you use/convert to .png image (with the same function you have used):

Solution 1

I was getting the same issue. I have windows and Python 3.6. So I found two solutions for this either you use/convert to .png image (with the same function you have used):

photo = PhotoImage('xyz.png')
l = Label(image = photo)
l.pack()

or if you want to read .jpg file only then use PIL library to read and display an image like this:

from PIL import ImageTk, Image
img = ImageTk.PhotoImage(Image.open("xyz.jpg"))  
l=Label(image=img)
l.pack()

Solution 2

Install PIL/Pillow with:

pip install Pillow

or:

sudo pip install pillow
from PIL import Image
from PIL import ImageTk
import tkinter

image = Image.open('bll.jpg')
image = image.resize((20, 20))
image = ImageTk.PhotoImage(image)

canv = Canvas(root, width=80, height=80, bg='white')
canv.grid(row=2, column=3)

img = PhotoImage(file=image)

Also using .PNG instead of .JPG is better for Tkinter.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read