本文介绍了如何使用Python 2.7.8 | Anaconda 2.1.0(32位)加载png图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Anaconda下载了我的Python 2.7.我正在使用Windows 7.我尝试了以下操作:

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()

我收到以下错误消息:

ImportError: No module named _imagingtk

我认为我需要安装ImageTk,如何 ImportError:未命名模块_imagingtk 说.

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

但是如何在Windows上安装它?我应该在哪里键入此代码?

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

 $ pip install ImageTk

如果我尝试:

 import ImageTk

我没有收到任何错误.什么意思是ImageTk实际上已经安装了,对吗?

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

谢谢

推荐答案

ImageTk在软件包PIL中定义,应使用以下软件包安装:

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

pip install Pillow

PillowPIL的端口,可通过pip访问.现在像这样导入PIL:

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

from PIL import ImageTk

这篇关于如何使用Python 2.7.8 | Anaconda 2.1.0(32位)加载png图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 10:41