Image.show() Show or Display Image - Python Pillow Examples


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.

Examples

1. Show or display given image

In the following example, we will read an image and show it to the user in GUI using show() method.

Python Program

from PIL import Image

#read the image
im = Image.open("sample-image.png")

#show image
im.show()

Output

Python Pillow Show or Display Image using default GUI Program

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.

2. Display more than one 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.

Python Program

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()

Summary

In this tutorial of Python Examples, we learned how to show or display an image to user, using Python Pillow library.