In this article, we will learn hoe to load images from user system to Tkinter window using PIL module. This program will open a dialogue box to select the required file from any directory and display it in the tkinter window.
Install the requiredments –
Use this command to install Tkinter :
pip install python-tk
Use this command to install PIL :
pip install pillow
ImageTk module contains support to create and modify Tkinter BitmapImage and PhotoImage objects from PIL images and
filedialog is used for the dialog box to appear when you are opening file from anywhere in your system or saving your file in a particular position or place.
Function to create a Tkinder window consisting of a button –
The Button object is created with text ‘open image’. On clicking it the
open_image function will be invoked.
Function to place the image onto the window –
openfilename function will return the file name of image.
Function to return the file name chosen from a dialog box –
To run this code, save it by the extension
.py and then open
cmd (command prompt) and move to the location of the file saved and then write the following –
and press enter and it will run. Or can be run directly by simply double-clicking your
.py extension file.
- Rename a folder of images using Tkinter
- Reading Images With Python - Tkinter
- Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)
- Mahotas - Loading image as grey
- Loading Image using Mahotas - Python
- Loading Excel spreadsheet as pandas DataFrame
- CSS | Border Images
- CSS | Styling Images
- HTML | Images
- pgmagick - Add text in images
- Reading images in Python
- How to put images in a box without space using Bootstrap?
- Working with Images in Python
- Apply changes to all the images in given folder - Using Python PIL
- How to download Google Images using Python
- Python | Working with PNG Images using Matplotlib
- Python | Grayscaling of Images using OpenCV
- Python | Uploading images in Django
- Working with Images in Python using Matplotlib
- Extract images from video in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.