

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 place an image into a frame in Tkinter?
To place an image into a Tkinter frame, you can follow the steps given below −
Steps −
Import the required libraries and create an instance of tkinter frame. To open an image and place it inside the frame, we will use the Pillow (PIL) library.
Set the size of the frame using geometry method.
Create a frame and specify its height and width. Place the frame at the center of the window using place() method with anchor='center'.
Open an image using ImageTk.PhotoImage(Image.open("image"))
Next, create a label object inside the frame and pass the image inside the label.
Finally, run the mainloop of the application window
Example
# 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("700x500") frame = Frame(win, width=600, height=400) frame.pack() frame.place(anchor='center', relx=0.5, rely=0.5) # Create an object of tkinter ImageTk img = ImageTk.PhotoImage(Image.open("forest.jpg")) # Create a Label Widget to display the text or Image label = Label(frame, image = img) label.pack() win.mainloop()
Output
When we run the above code, it will display the following output −
- Related Questions & Answers
- How to place objects in the middle of a frame using tkinter?
- How to add an image in Tkinter?
- How to update an image in a Tkinter Canvas?
- Embedding a matplotlib animation into a tkinter frame
- How to resize an image using Tkinter?
- How to use an Image as a button in Tkinter?
- How to insert an image in a Tkinter canvas item?
- How to place text blocks over an image using CSS?
- How do I insert a JPEG image into a Python Tkinter window?
- How to add a row in an R data frame at a specific place?
- How to center an image in canvas Python Tkinter
- How to place text over an image with HTML and CSS?
- How to change Entry.get() into an integer in Tkinter?
- How to use an image for the background in tkinter?
- How to Move an Image in Tkinter canvas with Arrow Keys?
Advertisements