How to open PIL Image in Tkinter on Canvas?

Pillow package (or PIL) helps a lot to process and load images in Python projects. It is a free open-source library available in Python that adds support to load, process, and manipulate the images of different formats.

In order to open the Image in Tkinter canvas, we have to first import the library using from PIL import Image, ImageTk command. To display the image in our Tkinter application, we can use the Canvas widget by specifying the image file in the create_image(x,y,image) method.


#Import the required Libraries
from tkinter import *
from PIL import Image,ImageTk

#Create an instance of tkinter frame
win = Tk()

#Set the geometry of tkinter frame

#Create a canvas
canvas= Canvas(win, width= 600, height= 400)

#Load an image in the script
img= ImageTk.PhotoImage("download.png"))

#Add image to the Canvas Items



Running the above code will display a window with an image inside the canvas widget.