beetlebug▾
/

ttk::labelframe

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

CommandDescription
ttk::labelframe stateGives the state flags of the widget, or turns flags on and off.
ttk::labelframe instateTests the state flags of the widget, and runs a script when they match.
ttk::labelframe identifyGives the name of the element of the widget at a point.
ttk::labelframe cgetGives the value of an option of the widget.
ttk::labelframe configureGives or sets the options of the widget.

Options

OptionTypeDefaultDatabase nameDescription
-borderwidthscreen distanceemptyborderWidthThe width of the border, in place of the border of the style.
-classclass nameemptyThe class of the widget for the option database and for the bindings, set only at creation.
-cursorcursor nameemptycursorThe shape of the pointer over the widget.
-heightscreen distance0heightThe height that the widget asks for when no geometry manager sets it from the children.
-labelanchorlabel anchornwlabelAnchorThe place of the label on the border.
-labelwidgetwidget pathemptylabelWidgetA widget to show on the border in place of the text.
-paddinglist of distancesemptypaddingThe space between the border and the children, in place of the padding of the style.
-reliefreliefemptyreliefThe 3-D look of the border.
-stylestyle nameemptystyleThe style of the widget, such as TLabelframe or a style of the script such as Accent.TLabelframe.
-takefocusboolean, empty, or scriptemptytakeFocusWhether the Tab key can move the focus to the widget.
-textstringemptytextThe title on the border.
-underlineinteger-1underlineThe index of a character of the title to underline, for a keyboard shortcut.
-widthscreen distance0widthThe 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.

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
hand2

ztk 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.

ttk::labelframe with -text Name -width 120 and -height 30-height 30ttk::labelframe with -text Name -width 120 and -height 60-height 60
Each with -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.

ttk::labelframe with -text Name -width 120 -height 50 and -labelanchor nw-labelanchor nwttk::labelframe with -text Name -width 120 -height 50 and -labelanchor n-labelanchor nttk::labelframe with -text Name -width 120 -height 50 and -labelanchor ne-labelanchor nettk::labelframe with -text Name -width 120 -height 50 and -labelanchor sw-labelanchor swttk::labelframe with -text Name -width 120 -height 50 and -labelanchor s-labelanchor sttk::labelframe with -text Name -width 120 -height 50 and -labelanchor se-labelanchor se
Each with -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
.tlflw

ztk 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]}
1

ztk stores each value at configure, as Tk 8.6.16 does.

-relief RELIEF

The 3-D look of the border.

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.

ttk::labelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief flat-relief flatttk::labelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief raised-relief raisedttk::labelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief sunken-relief sunkenttk::labelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief groove-relief groovettk::labelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief ridge-relief ridgettk::labelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief solid-relief solid
Each with -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.TLabelframe

ztk 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
1

ztk 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.

ttk::labelframe with -width 120 -height 50 and -text Name-text Namettk::labelframe with -width 120 -height 50 and -text {Full name}-text {Full name}
Each with -width 120 -height 50.
% ttk::labelframe .tlftx -text Hi
> ttk::labelframe .tlftx2 -text "Hi there everyone"
> expr {[winfo reqwidth .tlftx2] > [winfo reqwidth .tlftx]}
1

Each 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.

ttk::labelframe with -text Name -height 50 and -width 60-width 60ttk::labelframe with -text Name -height 50 and -width 120-width 120
Each with -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 PIXELS

Returns

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

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also