- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 images with ImageTk.PhotoImage with Tkinter
The PIL or Pillow library in Python is used for processing images in a Tkinter application. We can use Pillow to open the images, resize them and display in the window. To resize the image, we can use image_resize((width, height) **options) method. The resized image can later be processed and displayed through the label widget.
Let us have a look at the example where we will open an image and resize it to display in the window through the label widget.
# Import the required libraries from tkinter import * from PIL import Image, ImageTk # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") # Load the image image=Image.open('download.png') # Resize the image in the given (width, height) img=image.resize((450, 350)) # Conver the image in TkImage my_img=ImageTk.PhotoImage(img) # Display the image with label label=Label(win, image=my_img) label.pack() win.mainloop()
Running the above code will display a resized image in the window.
- How to use images in Tkinter using photoimage objects?
- Resizing pictures in PIL in Tkinter
- How to control automated window resizing in Tkinter?
- How to stop Tkinter Message widget from resizing?
- Stegosploit: Hacking with Images
- Dynamically Resize Buttons When Resizing a Window using Tkinter
- Working with Images in Python?
- Python - Display images with PyGame
- How to disallow resizing component with GridBagLayout in Java
- Convert Images to PDFs using Tkinter
- Blending two images with HTML5 canvas
- How to style images with CSS?
- Add style to images with Bootstrap
- Responsive Images in Bootstrap with Examples
- Using OpenCV with Tkinter