Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python (tkinter) error : "CRC check failed"

I'm doing a small GUI in python, and I wanna add a button with an image. So I'm following what's said here : https://www.geeksforgeeks.org/python-add-image-on-a-tkinter-button/

It gives :

downimage = PhotoImage(file = "Downloadimage.png")
Dowloadbutton = Button(window, image=downimage, font=("Source Code Pro Light", 20), bg='black', fg='lime', command=start)
Dowloadbutton.pack()

As it is said in the link. But then the magic happens :

Traceback (most recent call last):
  File "Keylogger.pyw", line 28, in <module>
    downimage = PhotoImage(file = "Downloadimage.png")
  File "C:\Users\Elève\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 3545, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Users\Elève\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 3501, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: CRC check failed

Line 28 corresponds to downimage = PhotoImage(file = "Downloadimage.png"). Everything else is packed and appear, but my button doesn't and gives me that error. I don't know what it means, when I try to search it on internet, a lot of non-tkinter-related results appear, it seems to be not a common but still known error.

(I'm using the last version of both python and tkinter)

If you can help me, thank you really much ! Have a nice day ;)

like image 309
Quantum Sushi Avatar asked Mar 02 '23 11:03

Quantum Sushi


1 Answers

In png format,CRC code is here.

(An example png image) enter image description here

It was encrypted(CRC32) by image chunk[0].It is a little hard for me to express that.

But the cause of your problem is the width and height of image is incorrect(mostly).Your image size has been revised.


In fact,if you put your image in linux,the image couldn't be opened normally.In windows default image viewer,system will ignore CRC checksum error,and you could open it.

How to solve your problem?

  1. Revise this image bytes.
  2. Use a new,correct image.
like image 195
jizhihaoSAMA Avatar answered Mar 30 '23 11:03

jizhihaoSAMA