An Error Occured To Add Picture In Python
I am new in python and I am using python 3.5 version. I want to add photo to python, and here's the code I wrote: from tkinter import * win=Tk() win.title('Python Image') canvas=C
Solution 1:
Photoimage can natively only load png
and pgm&ppm
images (http://effbot.org/tkinterbook/photoimage.htm).
You can load other image formats via PIL. For python3 use Pillow like this:
from PIL import Image, ImageTk
from tkinter import Tk,Canvas,NW
win=Tk()
win.title("Python Image")
canvas=Canvas(win,width=500,height=500)
canvas.pack()
# use your path here ...
my_image = ImageTk.PhotoImage(Image.open(r"some.jpg"))
canvas.create_image(0,0,anchor=NW,image= my_image )
win.mainloop()
You could have found all this information in NorthCats answer to How do I insert a JPEG image into a python Tkinter window? as well.
Post a Comment for "An Error Occured To Add Picture In Python"