Python Tkinter Frame

Tkinter Frame widget is a container that holds other Tkinter widgets like Label, Entry, Listbox, etc.

In this tutorial, we will learn how to create a Frame widget and how to use it group other widgets in a GUI window.

Create Tkinter Frame

To create a Tkinter Frame widget, use the following syntax.

w = Frame(parent, option, ...)

where parent is the root window or another frame in which this frame is displayed.

You can provide any number of Frame widget options, to change the visual and behavioral aspects of this Frame.

Example 1 – Tkinter Frame

In this example, we will create a Tkinter Frame that holds labels, button and entry widgets.

example.py – Python Program

import tkinter as tk

window_main = tk.Tk(className='Tkinter - TutorialKart')
window_main.geometry("400x200")

frame_1 = tk.Frame(window_main, bg='#c4ffd2', width=200, height=50)
frame_1.pack()
frame_1.pack_propagate(0)

frame_2 = tk.Frame(window_main, bg='#ffffff', width=200, height=50)
frame_2.pack()
frame_2.pack_propagate(0)

#in frame_1
label_1 = tk.Label(frame_1, text='Name')
label_1.pack(side=tk.LEFT)
submit = tk.Entry(frame_1)
submit.pack(side=tk.RIGHT)

#in frame_2
button_reset = tk.Button(frame_2, text='Reset')
button_reset.pack(side=tk.LEFT)
button_submit = tk.Button(frame_2, text='Submit')
button_submit.pack(side=tk.RIGHT)

window_main.mainloop()

Output

Tkinter Frame

Conclusion

In this Python Tutorial, we learned how to create a Frame widget in our GUI application, and how to work with it, with the help of example programs.