How to load a png image with Python 2.7.8 |Anaconda 2.1.0 (32-bit)?

若如初见. 提交于 2019-12-23 21:39:07

问题


I download my Python 2.7 with Anaconda. I'm using windows 7. I tried following:

from Tkinter import Tk, Frame, Canvas
import ImageTk

t = Tk()
t.title("Transparency")

frame = Frame(t)
frame.pack()

canvas = Canvas(frame, bg="black", width=500, height=500)
canvas.pack()

photoimage = ImageTk.PhotoImage(file=r"test.png")
canvas.create_image(150, 150, image=photoimage)

t.mainloop()

I get following Error:

ImportError: No module named _imagingtk

I think I need to install ImageTk, how this ImportError: No module named _imagingtk says.

But how can I install it on Windows? Where should I type this code?

 $ pip install ImageTk

If I try:

 import ImageTk

I don't get any Error. What means ImageTk is actually already installed, right?

Thanks


回答1:


ImageTk is defined in the package PIL which you should install with:

pip install Pillow

Pillow is a port of PIL that is accessible through pip. Now import PIL like so:

from PIL import ImageTk


来源:https://stackoverflow.com/questions/27692716/how-to-load-a-png-image-with-python-2-7-8-anaconda-2-1-0-32-bit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!