Python Tkinter LabelFrame

In this tutorial, we will learn about Python Tkinter LabelFrame. Tkinter 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()  

Python Tkinter LabelFrame Output:

python tkinter labelframe

Various possible options in Python Tkinter LabelFrame:

Check out various available options in Python Tkinter LabelFrame.

OPTIONDESCRIPTION
bgThis option is used to set the background colour of the widget.
bdThis option is used to set the size of the border around the indicator. By default, it is 2 px.
containerThis option is used to make a LabelWidget act as a container. Set container=true to make LabelWidget a container. By default, it is false.
cursorThis option used to set the style of cursor like an arrow, dot etc
fgThis option is used to set the foreground colour of the widget.
fontThis option is used to set the font style in the widget.
heightThis option is used to set the height of the widget.
labelAnchorThis option is used to set the position of the label in the widget. By default, the position is NW(north-west).
labelWidgetThis option is used to set the widget for the label. By default, LabelFrame uses text as the label.
highlightbackgroundThis option is used to set the focus highlight border when the widget doesn’t have the focus.
highlightcolorThis option is used to set the colour of the highlight.
highlightthicknessThis option is used to set the width of the highlight border.
padxThis option is used to set the horizontal padding of the widget.
padyThis option is used to set vertical padding of the widget.
reliefThis helps us to set the style of the border by which is default GROOVE.
textThis option is used to set the text for the LabelFrame.
widthThis option is used to set the width of the widget(LabelFrame).
Spread the love