Introduction

In this article, I will explain how to add a Labelframe in Tkinter in Python.
Definition
The Labelframe keyword is used to create a simple container widget. Its primary purpose is to act as a container for complex window layouts.
Syntax
  1. w = Labelframe( a, option)
Parameters
a − This represents the parent window of the computer.
option − The list of most used options for this widget.
Option & Description
Program
  1. from tkinter import *
  2. a= Tk()
  3. a.geometry("400x400")
  4. labelframe=LabelFrame(a,text="c#corner",bg = "green",
  5. bd=10,width=100,height=50)
  6. labelframe.pack(side=TOP)
  7. a.mainloop()
Output
How To Add Labelframe In Tkinter In Python
  • Fg - The fg is used to change the normal foreground (text) color.
  • Font - The font is used to change the text font to be used for the labelframe.
  • Cursor - The cursor is used to set this option to a cursor name, the mouse cursor will change to that pattern when it is over the labelframe.
Program
  1. from tkinter import *
  2. a= Tk()
  3. a.geometry("400x400")
  4. labelframe=LabelFrame(a,text="welcome!,c#corner",width=200,cursor = "target",
  5. height=200,fg = "black", font = "Castellar")
  6. labelframe.pack(side=TOP)
  7. a.mainloop()
Output
How To Add Labelframe In Tkinter In Python
  • HighlightBackground - we used to focus highlight when the frame does not have a focus
  • HighlightColor - we used to show in the focus highlight when the frame has a focus.
  • HighlightThickness - we used the thickness of the focus highlight.
Program
  1. from tkinter import *
  2. a= Tk()
  3. a.geometry("400x400")
  4. labelframe=LabelFrame(a,text="welcome!,c#corner",width=200,
  5. height=200,highlightcolor="yellow",
  6. highlightbackground="red",highlightthickness=10)
  7. labelframe.grid(padx = 100, pady = 100)
  8. a.mainloop()
Output
How To Add Labelframe In Tkinter In Python

Conclusion

In this article, we have seen how to add a Labelframe in Tkinter in Python. I hope this article was useful to you. Thanks for reading!