【发布时间】: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”找到的东西,但没有任何效果。任何想法为什么会发生这种情况以及如何解决这个问题?
【问题讨论】:
-
你安装zlib了吗?
-
你可以试试 Pillow 代替 PIL,pypi.python.org/pypi/Pillow/2.2.1
标签: python python-2.7 tkinter python-imaging-library