我正在使用Tkinter编写GUI并希望在a中显示一个png文件Tkiner.Label.所以我有一些像这样的代码:
self.vcode.img = PhotoImage(data=open('test.png').read(), format='png')
self.vcode.config(image=self.vcode.img)
Run Code Online (Sandbox Code Playgroud)
此代码在我的Linux机器上正确运行.但是当我在我的Windows机器上运行它时,它失败了.我还在其他几台机器上测试过(包括windows和linux),它一直都失败了.
Traceback是:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1486, in __call__
return self.func(*args)
File "C:\Documents and Settings\St\client\GUI.py", line 150, in showrbox
SignupBox(self, self.server)
File "C:\Documents and Settings\St\client\GUI.py", line 197, in __init__
self.refresh_vcode()
File "C:\Documents and Settings\St\client\GUI.py", line 203, in refresh_vcode
self.vcode.img = PhotoImage(data=open('test.png').read(), format='png')
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', …Run Code Online (Sandbox Code Playgroud)