- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to resize an image using Tkinter?
To process images with Tkinter and other Python packages, we generally use the Pillow Package (or PIL) in Python. It provides a way to load, process, manipulate, convert, and helps to resize the images. The package can be installed by using the command pip install Pillow. Once the package is installed, we can import it using the ‘from PIL import Image, ImageTk’ command.
To resize an image using the PIL package, we have to follow these steps −
Install Pillow Package or PIL in the local machine.
Open the Image using Open(image_location) method.
Resize the given image using resize((w,h), Image. ANTIALIAS) method where ANTIALIAS removes the structural Padding from the Image around it.
Display the Image using Canvas create_image(x,y, image) method.
Example
#Import the required Libraries from tkinter import * from PIL import Image,ImageTk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x270") #Create a canvas canvas= Canvas(win, width= 600, height= 400) canvas.pack() #Load an image in the script img= (Image.open("download.png")) #Resize the Image using resize method resized_image= img.resize((300,205), Image.ANTIALIAS) new_image= ImageTk.PhotoImage(resized_image) #Add image to the Canvas Items canvas.create_image(10,10, anchor=NW, image=new_image) win.mainloop()
Output
Running the above code will display a window that will display a resized image in the Canvas.
- Related Articles
- How to resize an image in Android using Picasso?
- How to resize an image in OpenCV using Python?
- How to resize an Image C#?
- How to resize the background image to window size in Tkinter?
- How to Resize an image in Android using Picasso on Kotlin?
- How to resize an image in Node Jimp?
- How to auto-resize an image to fit a div container using CSS?
- How to resize an Entry Box by height in Tkinter?
- How to resize Image in Android App using Kotlin?
- PyTorch – How to resize an image to a given size?
- How to explicitly resize frames in tkinter?
- How to resize image in PHP?
- How to resize an UIImageView using Swift?
- How To Dynamically Resize Button Text in Tkinter?
- How to add an image in Tkinter?
