微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

tkinter PhotoImage 仍然不适用于某些 PNG 文件

如何解决tkinter PhotoImage 仍然不适用于某些 PNG 文件

PhotoImage 用于 pgm、PPM、GIF 和 PNG 格式的图像。从 Tk 8.6 开始支持后者。

有关我的环境的信息,

  • WIN10
  • Python 3.6.0
  • tkinter.TkVersion 8.6
  • tkinter.Tcl().eval('info patchlevel') 8.6.6

我的一些 PNG 文件在以下脚本中失败

from tkinter import *

root = Tk()

bg = PhotoImage(file='d:/Fandom.png')    # Failed here
bg_label = Label(root,image=bg)
bg_label.place(x=0,y=0,relwidth=1,relheight=1)

root.mainloop()

可以从以下位置下载不同的 PNG 文件

两个文件文件头对于 PNG 文件是相同的 89 50 4E 47 0D 0A 1A 0A。这两个文件都可以在很多软件下正常显示,比如 windows 文件管理器、ACDSEE、Paint ......

不同PNG文件的失败信息

# Fandom.png
Traceback (most recent call last):
  File "<module1>",line 5,in <module>
  File "C:\Software\Python\lib\tkinter\__init__.py",line 3539,in __init__
    Image.__init__(self,'photo',name,cnf,master,**kw)
  File "C:\Software\Python\lib\tkinter\__init__.py",line 3495,in __init__
    self.tk.call(('image','create',imgtype,) + options)
_tkinter.TclError: encountered an unsupported criticial chunk type "orNT"

# duck.png
Traceback (most recent call last):
  File "<module1>",) + options)
_tkinter.TclError: encountered an unsupported criticial chunk type "eXIf"

图书馆 Pillow (PIL) 可能有助于工作,但不是这里的问题。

我的问题是

  • python 3.6.x 和 tkinter 8.6 是否支持所有 PNG 文件
  • 如果没有,支持什么格式或版本的 PNG 文件

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。