Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_tkinter.TclError: encountered an unsupported criticial chunk type "exIf"

So I am trying to put some pictures into my window and whenever I run the program it gives me this error:

_tkinter.TclError: encountered an unsupported criticial chunk type "exIf"

I tried putting it into other formats, such as .jpg, .png and .gif, but they don't work. Can you please help me?

This is my code:

from tkinter import *
from tkinter import ttk

class Window:
def __init__(self, master):
    self.master = master
    master.iconbitmap('ta.ico')
    master.title('Tamagochi')
    master.minsize(width=480, height=240)
    master.maxsize(width=480, height=240)

    self.pic1 = PhotoImage(file='pic1.png')
    self.pic2 = PhotoImage(file='pic2.png')
    self.pic3 = PhotoImage(file='pic3.png')
    self.pic4 = PhotoImage(file='pic4.png')

    self.smFrame = ttk.Frame(master)
    self.smButton1 = ttk.Button(self.smFrame, text='Start', command=self.start)
    self.smButton2 = ttk.Button(self.smFrame, text='Options', command=self.options)
    self.smButton3 = ttk.Button(self.smFrame, text='Quit', command=self.quit)
    self.smPhoto1 = ttk.Label(self.smFrame, image=self.pic1)

    self.smFrame.pack()
    self.smPhoto1.grid()
    self.smButton1.grid(pady=40, padx=200)
    self.smButton2.grid(pady=0, padx=200)
    self.smButton3.grid(pady=40, padx=200)
def start(self):
    pass
def options(self):
    pass
def quit(self):
    exit()
root = Tk()
Window(root)
root.mainloop()

This is the full error:

Traceback (most recent call last):
  File "C:/Users/NemPl/Desktop/ProLan/Python/Python programi/Tamagochi/Tamagochi.py", line 35, in <module>
    Window(root)
  File "C:/Users/NemPl/Desktop/ProLan/Python/Python programi/Tamagochi/Tamagochi.py", line 14, in __init__
    self.pic3 = PhotoImage(file='pic3.png')
  File "C:\Users\NemPl\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3539, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Users\NemPl\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3495, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: encountered an unsupported criticial chunk type "exIf"
like image 298
NemPlayer Avatar asked Mar 11 '17 08:03

NemPlayer


2 Answers

PhotoImage is a tkinter class which, unfortunately, can not deal with .png files.

The solution is to rely on the Python Imaging Library1 which offers support to several image formats and transforms them to image objects that can be "understood" by tkinter:

from PIL import Image, ImageTk

self.img1 = Image.open("pic1.png")
self.pic1 = ImageTk.PhotoImage(self.img1)

1. You can install PIL as described here.

like image 200
Billal Begueradj Avatar answered Sep 19 '22 01:09

Billal Begueradj


Just wanted to share a solution that solved for me!

I figured out that other '.png' images were working with the same code, so the problem was happening with the image file.

What solved my problem was simply modifying the image (just saved it from a image editor).

like image 42
Gabriel Tsutomu Avatar answered Sep 19 '22 01:09

Gabriel Tsutomu