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.
SyntaxImage.resize((width, height), resample=Image.BICUBIC)
Parameters:
You need to install Pillow (a modern fork of the Python Imaging Library):
2. Tkinter Installation Notepip install pillow
Windows & macOS: Tkinter comes pre-installed with Python.
Linux (some distros): You may need to install it manually.
On Ubuntu/Debian:
Step-by-Step Implementation Step 1: Import Required Libraries Pythonsudo apt-get install python3-tk
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:-
250x200Explanation:
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