- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 do I insert a JPEG image into a Python Tkinter window?
Python provides the Pillow (PIL) package to support, process, and display the images in tkinter applications. A Tkinter application generally supports image files such as, ppm, png, and gif.
Let us suppose we want to embed and display a JPEG or JPG image in our application.
Tkinter Label widgets are generally used to display the text or images on the window and thus by passing the img value, we can display the JPEG image in the window.
#Import required libraries from tkinter import * from PIL import ImageTk, Image #Create an instance of tkinter window win =Tk() #Define the geometry of the window win.geometry("650x400") #Initialize the file name in a variable path = "file.jpg" #Create an object of tkinter ImageTk img = ImageTk.PhotoImage(Image.open(path)) #Create a Label Widget to display the text or Image label = tk.Label(win, image = img) label.pack(fill = "both", expand = "yes") win.mainloop()
The code will display a JPEG image that is passed as the image value in the Label widget.
- Related Articles
- How do I close a tkinter window?
- How do I create a popup window using Tkinter?
- How do I create a popup window in Tkinter?
- How do I open a website in a Tkinter window?
- How do I create a popup window using Tkinter Program?
- How do I set a minimum window size in Tkinter?
- How do I position the buttons on a Tkinter window?
- How do I get rid of the Python Tkinter root window?
- How do I get the width and height of a Tkinter window?
- How do I handle the window close event in Tkinter?
- How do I use Window Manager (wm) attributes in Tkinter?
- How to display an image/screenshot in a Python Tkinter window without saving it?
- How do I insert a record from one Mongo database into another?
- How to insert an image in a Tkinter canvas item?
- How do I get the id after INSERT into MySQL database in Python?