Python Tkinter Frame

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

Syntax to add Python Tkinter Frame:

w = Frame (master, options)  
  • master: This represents the parent window.
  • options: Here 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() 

Various possible options in Python Tkinter Frame:

Option Description
bg This option helps us to set background colour displayed behind the widget.
bd This option helps us to set the width of the border around the widget. By default size of the border is 2px.
cursor This option helps us to set the style of cursor like an arrow, dot etc
height This option helps us to set the height of Frame.
width This option helps us to set the width of Frame.
Spread the love
Scroll to Top
×