【发布时间】:2018-10-18 08:30:33
【问题描述】:
我正在尝试使用 python 和 tkinter 在屏幕上显示图像,但是当我运行它时,它会在 PhotoImage 对象中出现错误。 这是我的代码:
from tkinter import *
root = Tk()
photo = PhotoImage(file="devil.png")
label = Label(root, image=photo)
label.pack()
root.mainloop()
图像文件与 .py 文件位于同一文件夹中。
它给出了这个错误:
Traceback (most recent call last):
File "C:/Users/MyUsername/PycharmProjects/GUI test/home.py", line 5, in <module>
photo = PhotoImage(file="devil.png")
File "C:\Users\MyUsername\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3542, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\MyUsername\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3498, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: encountered an unsupported criticial chunk type "iDOT"
有谁知道如何解决这个问题?
【问题讨论】:
-
您尝试过不同的图像吗?我已经使用我自己的 .png 运行了您的示例,效果很好。你在什么系统上等等。
-
非常感谢,确实是文件打不开
-
:) 没问题。 Cebrail 添加了一个很好的答案。
标签: python user-interface tkinter