【问题标题】:_tkinter.TclError: couldn't recognize data in image file_tkinter.TclError:无法识别图像文件中的数据
【发布时间】: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


【解决方案1】:

卸载 anaconda3(位于我的主目录中)解决了问题,它具有较低版本的 tkinter,python 导入了它而不是更好的版本。

我认为它可以通过更新 anaconda3 包来解决,但对我来说是不必要的。

感谢 @Lafexlos 告诉我检查版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-28
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 1970-01-01
    • 2019-05-05
    • 2020-05-26
    相关资源
    最近更新 更多