Python – Display Image using PIL
To show or display an image in Python Pillow, you can use show() method on an image object.
The show() method writes the image to a temporary file and then triggers the default program to display that image. Once the program execution is completed, the temporary file will be deleted.
Example 1: Show or Display Image in Pillow
In the following example, we will read an image and show it to the user in GUI using show() method.
from PIL import Image #read the image im = Image.open("sample-image.png") #show image im.show()
In this scenario, we are using Windows PC and Photos is the default program to opoen .BMP images. Hence, Pillow show() method displayed the image using Photos program.
Example 2: Show or Display Image in Pillow
You can display multiple images. All the images will be stacked up as the show() method triggers individual instances of the default program that displays an image in your computer.
In the following example, we will read multiple images and show them to the user in GUI using show() method.
from PIL import Image #read the image im1 = Image.open("sample-image.png") im2 = Image.open("test-image.png") #show images im1.show() im2.show()
In this tutorial of Python Examples, we learned how to show or display an image to user, using Python Pillow library.