Tkinter TCL错误:无法';“无法识别图像文件中的数据”;背景.png“;
最近,我切换到了Python2.7(从3.4版开始),在使用Tkinter Photoimage类读取.png文件时遇到了问题。我说:Tkinter TCL错误:无法';“无法识别图像文件中的数据”;背景.png“;,tkinter,Tkinter,最近,我切换到了Python2.7(从3.4版开始),在使用Tkinter Photoimage类读取.png文件时遇到了问题。我说: background = "background.png" photo = tk.PhotoImage(file=background) 但我得到了这个错误: Traceback (most recent call last): File "main.py", line 36, in <module> photo = tk.PhotoI
background = "background.png"
photo = tk.PhotoImage(file=background)
但我得到了这个错误:
Traceback (most recent call last):
File "main.py", line 36, in <module>
photo = tk.PhotoImage(file=background)
File "c:\Python27\lib\lib-tk\Tkinter.py", line 3323, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "c:\Python27\lib\lib-tk\Tkinter.py", line 3279, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "background.png"
回溯(最近一次呼叫最后一次):
文件“main.py”,第36行,在
photo=tk.PhotoImage(文件=背景)
文件“c:\Python27\lib\lib tk\Tkinter.py”,第3323行,在uu init中__
图像。_u初始(自我,“照片”,名称,cnf,主机,**千瓦)
文件“c:\Python27\lib\lib tk\Tkinter.py”,第3279行,在uu init中__
self.tk.call(('image','create',imgtype,name,)+选项)
_tkinter.TclError:无法识别图像文件“background.png”中的数据
img = ImageTk.PhotoImage(Image.open(background))