Horje
How to Display Images within Tkinter Frames

Tkinter is a Python module used to create Graphical User Interface (GUI) applications. Tkinter has many widgets such as Button, Label, Text, Entry, Frame, Checkbox and more that make it easy and quick to develop desktop applications.

How to Insert Image inside Frame in Tkinter?

To insert an image inside a frame is the same as inserting an image in Tkinter root GUI. The parent of the widget containing the image must refer to the frame name.

Example:

In this example, initially, we are creating a Frame in the GUI window. Then place an image in a Label widget. Then the label widget is placed inside the frame in Tkinter.

Python
# Importing Tkinter
import tkinter as tk
# GUI
root = tk.Tk()
root.title("GFG")
root.geometry("400x200")
# Convert image to PhotoImage variable.
gfg_picture = tk.PhotoImage(file="horje-logo.png")
# Frame created.
frame1 = tk.Frame(root, width=300, height=150)
frame1.pack()
# Label within the frame containing the image.
label1 = tk.Label(frame1, image=gfg_picture)
label1.pack()
root.mainloop()

Output:

insert_image_in_frame_tkinter_output_pic_1

GUI window with image inside frame




Reffered: https://www.geeksforgeeks.org


Python

Related
How to Fix "TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'" in Python How to Fix "TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'" in Python
How to Fix "AttributeError: 'SimpleImputer' Object Has No Attribute '_validate_data' in PyCaret" using Python? How to Fix "AttributeError: 'SimpleImputer' Object Has No Attribute '_validate_data' in PyCaret" using Python?
Python Pyramid - Cookiecutter Python Pyramid - Cookiecutter
How to fix 'Variable not defined' in custom modules in Python How to fix 'Variable not defined' in custom modules in Python
What does -> mean in Python function definitions? What does -> mean in Python function definitions?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
18