Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 381
Hangon Avatar asked Dec 11 '25 21:12

Hangon


1 Answers

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
like image 157
Malik Brahimi Avatar answered Dec 14 '25 19:12

Malik Brahimi