Hangon
Hangon

Reputation: 2619

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

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

Upvotes: 3

Views: 3526

Answers (1)

Malik Brahimi
Malik Brahimi

Reputation: 16721

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

Upvotes: 1

Related Questions