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

I am downloading my Python 2.7 using Anaconda. I am using windows 7. I have tried the 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 am getting the following error:

ImportError: No module named _imagingtk

      

I think I need to install ImageTk like this ImportError: No module named _imagingtk .

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

 $ pip install ImageTk

      

If I try:

 import ImageTk

      

I have no errors. Which means ImageTk is actually already installed, right?

thank

+3


source to share


1 answer


ImageTk

is defined in the package PIL

that you have to install with:

pip install Pillow

      



Pillow

is a port PIL

accessible through pip

. Now import PIL

like this:

from PIL import ImageTk

      

+1


source







All Articles