【发布时间】:2017-08-17 13:31:48
【问题描述】:
你好
所以我有一个 Tkinter GUI 程序,它从一开始就使用 .png 图像。
我使用 PyCharm,它在 Python3 和 Tkinter 上运行良好,无需任何外部模块。
但是当我从终端运行它时,我得到了这个:
someUser@somePC:~/KeyRunner$ python3 windowLOGIN.py
Traceback (most recent call last):
File "windowLOGIN.py", line 141, in <module>
app = WindowLogin(root)
File "windowLOGIN.py", line 23, in __init__
img = tk.PhotoImage(file="keyrunnerlogo.png")
File "/home/someUser/anaconda3/lib/python3.6/tkinter/__init__.py", line 3539, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/home/someUser/anaconda3/lib/python3.6/tkinter/__init__.py", line 3495, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "keyrunnerlogo.png"
如果我用 sudo 运行它,它运行正常,知道什么可以解决这个问题吗?
【问题讨论】:
-
你的 tkinter 版本是多少?
import tkinter; tkinter.TkVersion -
@Lafexlos 我的 tkinter 版本是 8.5
-
超级用户启动python是8.6,ok。
-
所以我认为它从 Anaconda 获取了错误的 Tkinter 版本。
-
很高兴你解决了。 :)
标签: python image python-3.x tkinter png