(new in Tk 8.4) The LabelFrame widget is a variant of the tkinter Frame widget. By default, it draws a border around its child widgets, and it can also display a title.
When to use the LabelFrame Widget
The LabelFrame can be used when you want to group a number of related widgets, such as a number of radiobuttons.
Patterns #
To display a group, create a LabelFrame, and add child widgets to the frame as usual. The widget draws a border around the children, and a text label above them.
from tkinter import * master = Tk() group = LabelFrame(master, text="Group", padx=5, pady=5) group.pack(padx=10, pady=10) w = Entry(group) w.pack() mainloop()
You can use options to control where and how to draw the label, and how to draw the border. See below for details.
Reference #
- LabelFrame(master=None, **options) (class) [#]
-
A frame widget with an internal group border and an opertional label.
- master
- Parent widget.
- **options
- Widget options. See the description of the config method for a list of available options.
- config(**options) [#]
-
Modifies one or more widget options. If no options are given, the method returns a dictionary containing all current option values.
- **options
- Widget options.
- background=
- The background color to use in this frame. This defaults to the application background color. To prevent updates, set the color to an empty string. (the option database name is background, the class is Background)
- bd=
- Same as borderwidth.
- bg=
- Same as background.
- borderwidth=
- Border width. Defaults to 2 pixels. (borderWidth/BorderWidth)
- class=
- Default is Labelframe. (class/Class)
- colormap=
-
Some displays support only 256 colors
(some use even less). Such displays usually provide a
color map to specify which 256 colors to use. This
option allows you to specify which color map to use
for this frame, and its child widgets.
By default, a new frame uses the same color map as its parent. Using this option, you can reuse the color map of another window instead (this window must be on the same screen and have the same visual characteristics). You can also use the value “new” to allocate a new color map for this frame.
You cannot change this option once you’ve created the frame. (colormap/Colormap) - container=
-
If true, this frame is a container widget.
Defaults to false.
You cannot change this option once you’ve created the frame. (container/Container) - cursor=
- The cursor to show when the mouse pointer is placed over this widget. Default is a system specific arrow cursor. (cursor/Cursor)
- fg=
- Same as foreground.
- font=
- Font to use for the label text. The default is system specific. (font/Font)
- foreground=
- Color to use for the label text. The default is system specific. (foreground/Foreground)
- height=
- Frame height, in pixels. No default value. (height/Height)
- highlightbackground=
- Together with highlightcolor, this option controls how to draw the focus highlight border. This option is used when the widget doesn’t have focus. The default is system specific. (highlightBackground/HighlightBackground)
- highlightcolor=
- Same as highlightbackground, but is used when the widget has focus. (highlightColor/HighlightColor)
- highlightthickness=
- The width of the focus highlight border. The default is typically a few pixels. (highlightThickness/HighlightThickness)
- labelanchor=
- Where to draw the label text. Default is NW (upper left corner). (labelAnchor/LabelAnchor)
- labelwidget=
- Widget to use for the label. If omitted, the frame uses the text option. No default value. (labelWidget/LabelWidget)
- padx=
- Horizontal internal padding. Default is 0. (padX/Pad)
- pady=
- Vertical internal padding. Default is 0. (padY/Pad)
- relief=
- Border style. The default is GROOVE. Other possible values are FLAT, RAISED, SUNKEN, and RIDGE. (relief/Relief)
- takefocus=
- If true, indicates that the user can use the Tab key to move to this widget. Default is 0 (false). (takeFocus/TakeFocus)
- text=
- The label text. (text/Text)
- visual=
- Screen visual. No default value. (visual/Visual)
- width=
- Frame width. No default value. (width/Width)