Python Tkinter LabelFrame

python tutorials and learn python

Created with Sketch.

Tkinter LabelFrame

The LabelFrame widget is used to draw a border around its child widgets. We can also display the title for the LabelFrame widget. It acts like a container which can be used to group the number of interrelated widgets such as Radiobuttons.

This widget is a variant of the Frame widget which has all the features of a frame. It also can display a label.

The syntax to use the LabelFrame widget is given below.

Syntax

  1. w = LabelFrame(top, options)

A list of options is given below.

SNOptionDescription
1bgThe background color of the widget.
2bdIt represents the size of the border shown around the indicator. The default is 2 pixels.
3ClassThe default value of the class is LabelFrame.
4colormapThis option is used to specify which colomap is to be used for this widget. By colormap, we mean the 256 colors that are used to form the graphics. With this option, we can reuse the colormap of another window on this widget.
5containerIf this is set to true, the LabelFrame becomes the container widget. The default value is false.
6cursorIt can be set to a cursor type, i.e. arrow, dot, etc. the mouse pointer is changed to the cursor type when it is over the widget.
7fgIt represents the foreground color of the widget.
8fontIt represents the font type of the widget text.
9heightIt represents the height of the widget.
10labelAnchorIt represents the exact position of the text within the widget. The default is NW(north-west)
11labelwidgetIt represents the widget to be used for the label. The frame uses the text for the label if no value specified.
12highlightbackgroundThe color of the focus highlight border when the widget doesn’t have the focus.
13highlightcolorThe color of the focus highlight when the widget has the focus.
14highlightthicknessThe width of the focus highlight border.
15padxThe horizontal padding of the widget.
16padyThe vertical padding of the widget.
17reliefIt represents the border style. The default value is GROOVE.
18textIt represents the string containing the label text.
19widthIt represents the width of the frame.

Example

  1. # !/usr/bin/python3
  2. from tkinter import *
  3. top = Tk()
  4. top.geometry(“300×200”)
  5. labelframe1 = LabelFrame(top, text=“Positive Comments”)
  6. labelframe1.pack(fill=“both”, expand=“yes”)
  7. toplabel = Label(labelframe1, text=“Place to put the positive comments”)
  8. toplabel.pack()
  9. labelframe2 = LabelFrame(top, text = “Negative Comments”)
  10. labelframe2.pack(fill=“both”, expand = “yes”)
  11. bottomlabel = Label(labelframe2,text = “Place to put the negative comments”)
  12. bottomlabel.pack()
  13. top.mainloop()

Output:

Python Tkinter LabelFrame

 

Leave a Reply

Your email address will not be published. Required fields are marked *