我想开始在python中使用Tkinter并有以下代码:
#!/usr/bin/python
from Tkinter import *
from PIL import ImageTk, Image
top = Tk()
dir(top)
top.title("Erstes Frame")
erstesFrame = Frame(top, height=250, width=250)
erstesFrame.pack_propagate(0)
erstesFrame.pack()
img = ImageTk.PhotoImage(Image.open("mario.gif"))
erstesBild = Label(erstesFrame, image = img)
erstesBild.pack()
top.mainloop()
但是当我尝试执行它时,它只会给我这个错误:
Traceback (most recent call last):
File "ToDoAPP.py", line 14, in <module>
img = ImageTk.PhotoImage(Image.open("mario.gif"))
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageTk.py", line 116, in __init__
self.paste(image)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageTk.py", line 181, in paste
import _imagingtk
ImportError: No module named _imagingtk
我用python-pip安装了PIL,我的操作系统是ubuntu 12.04,我的python版本是2.7.3
您需要安装ImageTk
模块。
在debian ubuntu中,您可以使用以下命令进行安装:
sudo apt-get install python-imaging-tk
更新
如果您使用的是最新版本的ubuntu(16.04+),则软件包名称已更改。
python-pil.imagetk
(Python 2.x)python3-pil.imagetk
(Python 3.x)本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句