ttk::labelframe
Guide: Themed widgets (ttk)
Makes a themed labelframe: a frame with a border and a title.
ttk::labelframe PATHNAME ?OPTION VALUE ...?
Description
Makes a themed labelframe with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. The labelframe shows its -text, or the widget of -labelwidget, on its border. Its children go in it with pack, grid, or place.
The parent of PATHNAME must exist, and PATHNAME must not. The class of the labelframe is TLabelframe, the name of its style. In ztk the labelframe uses the code and the CSS rules of the classic labelframe.
Widget commands
| Command | Description |
|---|---|
ttk::labelframe state | Gives the state flags of the widget, or turns flags on and off. |
ttk::labelframe instate | Tests the state flags of the widget, and runs a script when they match. |
ttk::labelframe identify | Gives the name of the element of the widget at a point. |
ttk::labelframe cget | Gives the value of an option of the widget. |
ttk::labelframe configure | Gives or sets the options of the widget. |
Options
| Option | Type | Default | Database name | Description |
|---|---|---|---|---|
-borderwidth | screen distance | empty | borderWidth | The width of the border, in place of the border of the style. |
-class | class name | empty | The class of the widget for the option database and for the bindings, set only at creation. | |
-cursor | cursor name | empty | cursor | The shape of the pointer over the widget. |
-height | screen distance | 0 | height | The height that the widget asks for when no geometry manager sets it from the children. |
-labelanchor | label anchor | nw | labelAnchor | The place of the label on the border. |
-labelwidget | widget path | empty | labelWidget | A widget to show on the border in place of the text. |
-padding | list of distances | empty | padding | The space between the border and the children, in place of the padding of the style. |
-relief | relief | empty | relief | The 3-D look of the border. |
-style | style name | empty | style | The style of the widget, such as TLabelframe or a style of the script such as Accent.TLabelframe. |
-takefocus | boolean, empty, or script | empty | takeFocus | Whether the Tab key can move the focus to the widget. |
-text | string | empty | text | The title on the border. |
-underline | integer | -1 | underline | The index of a character of the title to underline, for a keyboard shortcut. |
-width | screen distance | 0 | width | The width that the widget asks for when no geometry manager sets it from the children. |
-borderwidth DISTANCE
The width of the border, in place of the border of the style.
The width of the border around the widget. An empty value uses the border of the style. With children, a wider border makes a larger widget. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.
% foreach {w bw} {.tlfbw {} .tlfbw9 9} {
> ttk::labelframe $w -text Title -borderwidth $bw
> ttk::label $w.l -text Hi
> pack $w.l
> }
> update
> expr {[winfo reqwidth .tlfbw9] > [winfo reqwidth .tlfbw]}
1% ttk::labelframe .tlfbw2 -borderwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS-class CLASS
The class of the widget for the option database and for the bindings, set only at creation.
The class name replaces the class of the style, such as TLabelframe, in winfo class and in the bind tags of the widget. Give it in the call that makes the widget. A later configure of the option gives an error.
% ttk::labelframe .tlfcl -class Fancy
> winfo class .tlfcl
Fancy
% ttk::labelframe .tlfcl3
> winfo class .tlfcl3
TLabelframe% ttk::labelframe .tlfcl2
> .tlfcl2 configure -class Other
attempt to change read-only option
-errorcode NONE-cursor CURSOR
The shape of the pointer over the widget.
Each value side by side: the contact sheet of the cursors
A cursor name of Tk, such as hand2 or xterm. An empty value uses the cursor of the parent.
% ttk::labelframe .tlfcu -cursor hand2
> .tlfcu cget -cursor
hand2ztk stores each value of the option with no check.
-height DISTANCE
The height that the widget asks for when no geometry manager sets it from the children.
With children managed by pack or grid, the children set the size, unless the script turns off the propagation with pack propagate or grid propagate. A value of 0 or less asks for no height of its own.

-height 30
-height 60-text Name -width 120.% ttk::labelframe .tlfhe -height 2c
> expr {[winfo reqheight .tlfhe] > 50}
1% ttk::labelframe .tlfhe2 -height x
bad screen distance "x"
-errorcode TK VALUE PIXELS-labelanchor ANCHOR
The place of the label on the border.
The first letter is the side of the border: n, s, e, or w. A second letter puts the label at that end of the side, such as nw for the left end of the top side, or en for the top end of the right side. One letter puts the label in the middle of that side.
Values: nw, n, ne, en, e, es, se, s, sw, ws, w, wn.

-labelanchor nw
-labelanchor n
-labelanchor ne
-labelanchor sw
-labelanchor s
-labelanchor se-text Name -width 120 -height 50.% ttk::labelframe .tlfla -text Title -labelanchor s
> .tlfla cget -labelanchor
s% ttk::labelframe .tlfla2 -labelanchor bogus
bad labelanchor "bogus": must be e, en, es, n, ne, nw, s, se, sw, w, wn, or ws
-errorcode TCL LOOKUP INDEX labelanchor bogus-labelwidget WIDGET
A widget to show on the border in place of the text.
The labelframe shows the widget at the place of the label, and the -text does not show. The widget is often a ttk::label or a ttk::checkbutton, a child of the labelframe or of its parent.
% ttk::checkbutton .tlflw -text Advanced
> ttk::labelframe .tlflw2 -labelwidget .tlflw
> .tlflw2 cget -labelwidget
.tlflwztk stores each value of the option with no check.
-padding PADDING
The space between the border and the children, in place of the padding of the style.
A list of 1 to 4 distances: left, top, right, and bottom. One value is the space at each side. A missing third value is the first, and a missing fourth value is the second. An empty value uses the padding of the style. With children managed by pack or grid, the padding adds to the size that they need.
% foreach {w pad} {.tlfpa {} .tlfpa30 30} {
> ttk::labelframe $w -padding $pad
> ttk::label $w.l -text Hi
> pack $w.l
> }
> update
> expr {[winfo reqwidth .tlfpa30] > [winfo reqwidth .tlfpa]}
1ztk stores each value at configure, as Tk 8.6.16 does.
-relief RELIEF
The 3-D look of the border.
Each value side by side: the contact sheet of the reliefs
The style of the border: raised and sunken look 3-D, and groove and ridge are lines. The border shows only with a -borderwidth above 0. An empty value uses the relief of the style.
Values: flat, groove, raised, ridge, solid, sunken.

-relief flat
-relief raised
-relief sunken
-relief groove
-relief ridge
-relief solid-text Name -borderwidth 4 -width 120 -height 50. The modern theme draws each relief but flat with the same border.% ttk::labelframe .tlfre -relief groove -borderwidth 2
> .tlfre cget -relief
groove% ttk::labelframe .tlfre2 -relief bumpy
bad relief "bumpy": must be flat, groove, raised, ridge, solid, or sunken
-errorcode TCL LOOKUP INDEX relief bumpy-style STYLE
The style of the widget, such as TLabelframe or a style of the script such as Accent.TLabelframe.
An empty value uses the style TLabelframe. A style name of the script ends with the name of the base style, such as Accent.TLabelframe, and ttk::style configure and ttk::style map give it its options. A style with no settings looks like its base style.
% ttk::style configure Accent.TLabelframe -foreground white
> ttk::labelframe .tlfsy -style Accent.TLabelframe
> .tlfsy cget -style
Accent.TLabelframeztk stores each value of the option with no check, as Tk 8.6.16 does at creation.
-takefocus VALUE
Whether the Tab key can move the focus to the widget.
1 puts the widget in the order of the Tab key, and 0 leaves it out. The default empty value uses the default rule of Tk, and this widget is not in the order of the Tab key with it. A script runs with the path of the widget appended, and its result is the answer.
% ttk::labelframe .tlftf -takefocus 1
> .tlftf cget -takefocus
1ztk stores each value of the option with no check.
-text TEXT
The title on the border.
The text that the labelframe shows at the place of -labelanchor. A longer text makes a wider labelframe.

-text Name
-text {Full name}-width 120 -height 50.% ttk::labelframe .tlftx -text Hi
> ttk::labelframe .tlftx2 -text "Hi there everyone"
> expr {[winfo reqwidth .tlftx2] > [winfo reqwidth .tlftx]}
1Each string is a valid text.
-underline INDEX
The index of a character of the title to underline, for a keyboard shortcut.
The index from 0 of the character of -text to underline. -1 underlines no character. The script binds the key itself.
% ttk::labelframe .tlfun -text Account -underline 0
> .tlfun cget -underline
0% ttk::labelframe .tlfun2 -underline x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-width DISTANCE
The width that the widget asks for when no geometry manager sets it from the children.
With children managed by pack or grid, the children set the size, unless the script turns off the propagation with pack propagate or grid propagate. A value of 0 or less asks for no width of its own.

-width 60
-width 120-text Name -height 50.% ttk::labelframe .tlfwi -width 100 -height 50
> list [winfo reqwidth .tlfwi] [winfo reqheight .tlfwi]
100 50% ttk::labelframe .tlfwi2 -width x
bad screen distance "x"
-errorcode TK VALUE PIXELSReturns
PATHNAME.
Examples
% ttk::labelframe .account -text Account -padding 8
> ttk::entry .account.name
> pack .account.name
> .account cget -text
Account
% winfo class [ttk::labelframe .box]
TLabelframe
Errors
% ttk::labelframe .x -foo a
unknown option "-foo"
-errorcode TK LOOKUP OPTION -foo
% ttk::labelframe .twice
> ttk::labelframe .twice
window name "twice" already exists in parent
-errorcode TK VALUE WINDOW EXISTS
# The parent .no does not exist.
% ttk::labelframe .no.f
bad window path name ".no"
-errorcode TK LOOKUP WINDOW .no
% ttk::labelframe
wrong # args: should be "ttk::labelframe pathName ?-option value ...?"
-errorcode TCL WRONGARGS
Differences from Tcl
-cursoraccepts each value with no check. Tk 8.6.16 gives an error for a cursor name that does not exist.- The errors of
state,instate,identify, and of an unknown widget command have the error codeNONE. Tk 8.6.16 gives a code such asTTK VALUE STATEorTCL LOOKUP INDEX. The error of-underlinehas the codeTCL VALUE NUMBER, where Tk 8.6.16 givesTCL VALUE INTEGER. - A bad
-labelanchorgives the error of the classiclabelframe,bad labelanchor "VALUE": must be .... Tk 8.6.16 givesBad label anchor specification VALUE. -labelwidgetaccepts the name of a widget that does not exist. Tk 8.6.16 gives the errorbad window path name.- The requested size differs from Tk 8.6.16. With no children, the labelframe asks for the width of its label. In Tk 8.6.16 it asks for 1 pixel.
- The states
activeandhoverare one flag, sostate activeturns on both.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1