- 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
Resizing pictures in PIL in Tkinter
Python provides Pillow or PIL package for image processing which is used to load, process, and customize the images in an application. It has many properties like Color of the image, Image Font, resizing the images, loading the image, etc.
In order to resize the Images in an application, we can use the resize(width, height) method. The method can be invoked after loading the image in the application. In order to open the image in the application, we have to import the package in the notebook as,
from PIL import Image, ImageTk
Example
In the following example, we have resized an image to "300x225".
#Import tkinter library from tkinter import * from PIL import Image, ImageTk #Create an instance of tkinter frame win= Tk() #Set the Geometry win.geometry("750x250") #Open a New Image image= Image.open("tutorialspoint.png") #Resize Image using resize function resized_image= image.resize((300,225), Image.ANTIALIAS) #Convert the image into PhotoImage img = ImageTk.PhotoImage(resized_image) #Create a label for the image Label(win,image= img).pack(pady=20) win.mainloop()
Output
Running the above code will display a window that contain an image with the size of "300x225".
Advertisements
To Continue Learning Please Login
Login with Google