显示png图像时Tkinter / ImageTk'AttributeError'(Tkinter/ImageTk 'AttributeError' when

系统教程 行业动态 更新时间:2024-06-14 16:59:17
显示png图像时Tkinter / ImageTk'AttributeError'(Tkinter/ImageTk 'AttributeError' when displaying a png image)

我试图在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 pillow

PIP应在你的机器上安装枕头,并安装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 pillow

PIP 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.

更多推荐

本文发布于:2023-04-16 14:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/b8f0f0706119b14b60eca403d11e7280.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   Tkinter   png   ImageTk   image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!