Open In App
Related Articles

How to resize Image in Python – Tkinter?

Improve Article
Improve
Save Article
Save
Like Article
Like

Prerequisite:

Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using Tkinter is an easy task.

In this article, we will learn how to resize an image using python in Tkinter. In Tkinter, there is no in-built method or any package to work with images. Here we will use pillow library for images.

Let’s Understand step by step implementation:-

  • Import Required Library

Python3




# Import Module
from tkinter import *
from PIL import Image, ImageTk


  • Read the image using the open() method in pillow library

Syntax: 

Image.open("Enter Image File Path", mode='r', **attr)

Python3




# Read the Image
image = Image.open("Image File Path")


  • Resize an image using resize() method. It returns a resized copy of this image.

Syntax: 

Image.resize((width,height) , resample=3, **attr)

Python3




# Resize the image using resize() method
resize_image = image.resize((width, height))


  • Add Label and add resized image

Python3




img = ImageTk.PhotoImage(resize_image)
 
# create label and add resize image
label1 = Label(image=img)
label1.image = img
label1.pack()


Below is the implementation: 

Python3




# Import Module
from tkinter import *
from PIL import Image, ImageTk
 
# Create Tkinter Object
root = Tk()
 
# Read the Image
image = Image.open("Image File Path")
 
# Resize the image using resize() method
resize_image = image.resize((width, height))
 
img = ImageTk.PhotoImage(resize_image)
 
# create label and add resize image
label1 = Label(image=img)
label1.image = img
label1.pack()
 
# Execute Tkinter
root.mainloop()


Output:- 

250×200

In the above example, enter the file name or path at the Image File Path and enter the value of width and height according to your need. 

 


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 31 Aug, 2021
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials