A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/how-to-resize-image-in-python-tkinter/ below:

How to resize Image in Python - Tkinter?

How to resize Image in Python - Tkinter?

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:- 

250x200

Explanation:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4