【问题标题】:Tkinter/ImageTk 'AttributeError' when displaying a png image显示 png 图像时的 Tkinter/ImageTk 'AttributeError'
【发布时间】:2013-12-04 20:13:37
【问题描述】:

我正在尝试借助 PIL 库中的 ImageTk 模块在 Tkinter 按钮小部件中使用 PNG 图像。

image = Image.open(os.path.join('icons','bulb.png')) # using PIL for png images
        self.correctGuessImage = ImageTk.PhotoImage(image)

虽然在 Windows 7x64 下运行良好,但它无法在 Linux Mint x64 上运行。我在运行同一个文件时遇到此错误。

  File "/home/user/Documents/temp.py", line 222, in drawButtons
    self.correctGuessImage = ImageTk.PhotoImage(image)
  File "/usr/lib/python2.7/dist-packages/PIL/ImageTk.py", line 121, in __init__
    self.paste(image)
  File "/usr/lib/python2.7/dist-packages/PIL/ImageTk.py", line 171, in paste
    im.load()
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line 192, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
AttributeError: 'module' object has no attribute '_getdecoder'

我从代表处安装了所有我能用“python”、“png”和“tk”找到的东西,但没有任何效果。任何想法为什么会发生这种情况以及如何解决这个问题?

【问题讨论】:

标签: python python-2.7 tkinter python-imaging-library


【解决方案1】:

我设法解决了这个奇怪的问题。如果您使用的是 Linux Mint,您将从销售代表那里安装枕头,不要!首先确保你有 tk8.5-devtcl8.5-dev 包并通过 PIP 安装 pillow

$ sudo pip install pillow

PIP 将在您的机器上安装 tk 和 tcl dev 包构建枕头,这将解决上述问题。确保您没有 python-imaging-compat 实际的 PIL 库,因为 Pillow 和 PIL 不兼容。我觉得这很令人沮丧,因为 HP 打印机的用户不会很高兴不能使用 hplip(python-imaging-compat 的依赖项)

我在this page 上找到了建议。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多