我试图在PIL库的ImageTk模块的帮助下在Tkinter Button小部件中使用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'安装了我能找到的所有内容但没有效果。 任何想法为什么会发生这种情况以及如何解决这个问题?
I am trying to use a PNG image in a Tkinter Button widget with the help of ImageTk module from PIL library.
image = Image.open(os.path.join('icons','bulb.png')) # using PIL for png images self.correctGuessImage = ImageTk.PhotoImage(image)While working fine under windows 7x64 it fails to work on Linux Mint x64. I am getting this error running the same file.
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'I installed everything I could find with 'python','png' and 'tk' from the reps but no effect. Any ideas why is this happening and how to fix this?
最满意答案
我设法解决了这个奇怪的问题。 如果您正在使用Linux Mint,那么您将从代表处安装枕头,不要! 首先确保你有tk8.5-dev和tcl8.5-dev软件包并通过PIP安装枕头 。
$ sudo pip install pillowPIP应在你的机器上安装枕头,并安装tk和tcl开发包,这将解决上述问题。 确保你没有python-imaging-compat实际的PIL库,因为Pillow和PIL是不兼容的。 我发现这非常令人沮丧,因为HP打印机的用户不乐意不能使用hplip(python-imaging-compat的依赖)
我在这个页面上找到了建议。
I managed to resolve this strange issue. If you're using Linux Mint, you'll be installing pillow from the reps, don't! First make sure you have tk8.5-dev and tcl8.5-dev packages and install pillow via PIP.
$ sudo pip install pillowPIP shall build pillow on your machine with tk and tcl dev packages installed, which shall resolve the problem mentioned above. Make sure you don't have python-imaging-compat the actual PIL library because Pillow and PIL are incompatible. I find this quite frustrating as users of HP printers won't be happy not to be able to use hplip (dependency of python-imaging-compat)
I found the advice on this page.
更多推荐
发布评论