Python Tkinter Frame

In this tutorial, we will learn about Python Tkinter Frame. Tkinter Frame widget is used for grouping of other Tkinter Widgets. It works as a container to other Widgets like Button, Entry etc. Frame widget occupies a rectangular area on the screen.

Syntax to add Python Tkinter Frame:

w = Frame (master, options)  
  • masterThis represents the parent window.
  • optionsHere is the list of most commonly used options for this widget.

Example:

from tkinter import *  
 
mainWindow = Tk()  

mainWindow.geometry("300x150")

frame = Frame(mainWindow)
frame.pack()

bottomframe = Frame(mainWindow)
bottomframe.pack( side = BOTTOM )

button1 = Button(frame, text="Button 1", bg="red", fg="white")
button1.pack( side = LEFT)

button2 = Button(frame, text="Button 2", bg="blue", fg="white")
button2.pack( side = LEFT )

button3 = Button(frame, text="Button 3", bg="green", fg="white")
button3.pack( side = LEFT )

button4 = Button(bottomframe, text="Button 4", bg="yellow", fg="black")
button4.pack( side = BOTTOM)

mainWindow.mainloop() 

Example:

Python Tkinter Frame

Various possible options in Python Tkinter Frame:

OptionDescription
bgThis option helps us to set background colour displayed behind the widget.
bdThis option helps us to set the width of the border around the widget. By default size of the border is 2px.
cursorThis option helps us to set the style of cursor like an arrow, dot etc
heightThis option helps us to set the height of Frame.
widthThis option helps us to set the width of Frame.
Spread the love