Python Tkinter LabelFrame

In this tutorial, we will learn about Python Tkinter LabelFrameTkinter LabelFrame acts as a container and used to create a border around child widgets.

LabelFrame widget has all the features of the frame. The thing which makes LabelFrame different from normal Frame widget is, it can show label as well.

Syntax to add Python Tkinter LabelFrame:

w = LabelFrame( master, option)
  • master: This represents the parent window.
  • options: Here is the list of most commonly used options for this widget.

Example Program of Python Tkinter LabelFrame:

from tkinter import *  
  
mainWindow = Tk()  
mainWindow.geometry("300x200")  
  
labelframe = LabelFrame(mainWindow, text="This is Label Frame")  
labelframe.pack(fill="both", expand="yes")  
  
label = Label(labelframe, text="This is Label inside in a LabelFrame")  
label.pack()    
  
mainWindow.mainloop()  

Various possible options in Python Tkinter LabelFrame:

Check out various available options in Python Tkinter LabelFrame.

OPTION DESCRIPTION
bg This option is used to set the background colour of the widget.
bd This option is used to set the size of the border around the indicator. By default, it is 2 px.
container This option is used to make a LabelWidget act as a container. Set container=true to make LabelWidget a container. By default, it is false.
cursor This option used to set the style of cursor like an arrow, dot etc
fg This option is used to set the foreground colour of the widget.
font This option is used to set the font style in the widget.
height This option is used to set the height of the widget.
labelAnchor This option is used to set the position of the label in the widget. By default, the position is NW(north-west).
labelWidget This option is used to set the widget for the label. By default, LabelFrame uses text as the label.
highlightbackground This option is used to set the focus highlight border when the widget doesn’t have the focus.
highlightcolor This option is used to set the colour of the highlight.
highlightthickness This option is used to set the width of the highlight border.
padx This option is used to set the horizontal padding of the widget.
pady This option is used to set vertical padding of the widget.
relief This helps us to set the style of the border by which is default GROOVE.
text This option is used to set the text for the LabelFrame.
width This option is used to set the width of the widget(LabelFrame).
Spread the love
Scroll to Top
×