【问题标题】:Tkinter PhotoImage error "encountered an unsupported criticial chunk type "iDOT""Tkinter PhotoImage 错误“遇到不受支持的关键块类型“iDOT””
【发布时间】: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


【解决方案1】:

您使用的图像块类型“iDOT”不是已注册的 PNG 块。因此,您应该将图像替换为合适的图像。

This can help you understand what actually error is about

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-28
    • 2021-11-11
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 2019-10-16
    相关资源
    最近更新 更多