How to resize Image in Python Tkinter? (original) (raw)

Last Updated : 07 Apr, 2025

Python provides multiple options for building GUI (Graphical User Interface) applications. Among them, Tkinter is one of the most widely used and simplest options. It comes bundled with Python and serves as a standard interface to the Tk GUI toolkit.

However, Tkinter alone does not provide support for advanced image operations such as **resizing. To work with images effectively, we use the Pillow library, which integrates smoothly with Tkinter and allows image processing tasks like resizing, cropping, rotating, etc.

In this article, we’ll learn how to resize an image in Python using Tkinter and Pillow and display it in a GUI window.

Syntax

Image.resize((width, height), resample=Image.BICUBIC)

**Parameters:

Installation

1. Install Pillow

You need to install Pillow (a modern fork of the Python Imaging Library):

pip install pillow

2. Tkinter Installation Note

**Windows & macOS: Tkinter comes **pre-installed with **Python.

**Linux (some distros): You may need to install it **manually.

**On Ubuntu/Debian:

sudo apt-get install python3-tk

Step-by-Step Implementation

Step 1: Import Required Libraries

Python `

from tkinter import * from PIL import Image, ImageTk

`

Step 2: Load the Image using Pillow

Python `

Read the Image

image = Image.open("Image File Path")

`

Step 3: Resize the Image

Python `

resized_image = image.resize((250, 200))

`

Step 4: Display the Image in Tkinter GUI

Python `

Convert the resized image for Tkinter

img = ImageTk.PhotoImage(resized_image)

Create a label and assign image

label = Label(image=img) label.image = img # Keep a reference to avoid garbage collection label.pack()

`

**Complete Code

Python `

from tkinter import * from PIL import Image, ImageTk

Create the main GUI window

root = Tk() root.title("Image Resizer")

image = Image.open("sample.jpg") # Replace with your image file path

resized_image = image.resize((250, 200))

img = ImageTk.PhotoImage(resized_image)

label = Label(image=img) label.image = img # Required to prevent image from being garbage collected label.pack()

Run the GUI application

root.mainloop()

`

**Output:-

250×200

**Explanation: