【问题标题】:TclError: couldn't recognize data in image file "background.png"TclError:无法识别图像文件“background.png”中的数据
【发布时间】:2017-11-26 17:36:19
【问题描述】:

我最近切换到 Python 2.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.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"

【问题讨论】:

    标签: tkinter


    【解决方案1】:
    img = ImageTk.PhotoImage(Image.open(background))
    

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多