How to Show Images with Pillow Library in Python

In this example, we will learn how to display images using the library Pillow with Python.
To open an image file, you need to use the open() function of the Image module. The usage is as follows: open(infile [, mode]) where

  • infile is the path to open the image file.
  • mode is the mode in which the file is opened, which is the same as the mode of the general file.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from tkinter import *
from PIL import Image, ImageTk

win = Tk()
win.title(string = "Show Images Using Pillow")

# the path you store your iamges
path = "F:/logos/"
imgFile1 = + "cmu-logo.png")
imgFile2 = + "mit-logo.png")
imgFile3 = + "stanford-logo.png")
imgFile4 = + "berkeley-logo.png")

img1 = ImageTk.PhotoImage(imgFile1)
img2 = ImageTk.PhotoImage(imgFile2)
img3 = ImageTk.PhotoImage(imgFile3)
img4 = ImageTk.PhotoImage(imgFile4)

canvas = Canvas(win, width=360, height=360)
canvas.create_image(40, 40, image=img1, anchor=NW)
canvas.create_image(220, 40, image=img2, anchor=NW)
canvas.create_image(40, 220, image=img3, anchor=NW)
canvas.create_image(220, 220, image=img4, anchor=NW)


4. Data

showImages: these are the images that we’re going to show.

5. Results

Notify of
Inline Feedbacks
View all comments