gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:56:50 25 4
gpt4 key购买 nike

所以我试图将一些图片放入我的窗口,但每当我运行该程序时,它都会给我这个错误:

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

我尝试将其转换为其他格式,例如 .jpg.png.gif,但它们不起作用。你能帮帮我吗?

这是我的代码:

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()

这是完整的错误:

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"

最佳答案

PhotoImage是一个 tkinter 类,不幸的是,它不能处理 .png 文件。

解决方案是依赖Python Imaging Library 1 提供对多种图像格式的支持,并将它们转换为可以被 tkinter理解”的图像对象:

from PIL import Image, ImageTk

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

<子>1.您可以按照说明安装 PIL here .

关于python - _tkinter.TclError : encountered an unsupported criticial chunk type "exIf",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42733286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com