beetlebug▾
/

labelframe

Makes a labelframe: a frame with a border and a label in the border.

labelframe PATHNAME ?OPTION VALUE ...?

Description

Makes a labelframe widget with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. A labelframe is a frame that draws a border with a label in a gap of the border. The label is the text of -text, or the widget of -labelwidget. A script puts other widgets inside it with a geometry manager, such as pack or grid.

The parent of PATHNAME must exist, and PATHNAME must not. A labelframe is a Labelframe in CSS and for the option database, unless -class gives it another class. ztk::class gives it a style class for a stylesheet.

-class, -colormap, -container, and -visual take a value only at the creation of the labelframe. configure of one of them gives an error.

Widget commands

CommandDescription
labelframe cgetGives the value of an option of the labelframe.
labelframe configureGives or sets the options of the labelframe.

Options

OptionTypeDefaultDatabase nameDescription
-borderwidthscreen distance0borderWidthThe width of the border of the labelframe.
-classstringLabelframeclassThe class of the labelframe for the option database and for bind.
-fontfontTkDefaultFontfontThe font of the label text.
-foregroundcolor#000000foregroundThe color of the label text.
-labelanchorlabelanchornwlabelAnchorThe place of the label on the border.
-labelwidgetwidget path nameemptylabelWidgetA widget to show in place of the label text.
-reliefreliefgroovereliefThe 3-D look of the border.
-textstringemptytextThe text of the label at the border of the labelframe.
-backgroundcolor#d9d9d9backgroundThe background color of the labelframe.
-colormapstringemptycolormapThe colormap of the labelframe, a feature of X11.
-containerboolean0containerWhether the labelframe holds the window of another application, a feature of X11.
-cursorcursor nameemptycursorThe shape of the pointer over the labelframe.
-heightscreen distance0heightThe height that the labelframe asks for.
-highlightbackgroundcolor#d9d9d9highlightBackgroundThe color of the focus ring while the labelframe has no focus, in the look of Tk on X11.
-highlightcolorcolor#000000highlightColorThe color of the focus ring while the labelframe has the focus, in the look of Tk on X11.
-highlightthicknessscreen distance0highlightThicknessThe width of the focus ring, in the look of Tk on X11.
-padxscreen distance0padXThe space between the left and the right sides of the labelframe and its children.
-padyscreen distance0padYThe space between the top and the bottom of the labelframe and its children.
-takefocusstring0takeFocusWhether the Tab key can move the focus to the labelframe.
-visualstringemptyvisualThe visual of the labelframe, a feature of X11.
-widthscreen distance0widthThe width that the labelframe asks for.

-borderwidth DISTANCE

The width of the border of the labelframe.

The width of the border around the labelframe. -bd is the same option. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.

labelframe with -text Name -width 120 -height 50 and -borderwidth 0-borderwidth 0labelframe with -text Name -width 120 -height 50 and -borderwidth 1-borderwidth 1labelframe with -text Name -width 120 -height 50 and -borderwidth 4-borderwidth 4
Each with -text Name -width 120 -height 50.
% labelframe .borderwidth -borderwidth 4
> .borderwidth cget -borderwidth
4
% labelframe .borderwidth2 -borderwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-class TEXT

The class of the labelframe for the option database and for bind.

The class name that winfo class gives. The option database and the bindings of the class use it. Set it only at the creation of the labelframe.

% labelframe .class -class Panel
> winfo class .class
Panel
% labelframe .class2; .class2 configure -class Other
can't modify -class option after widget is created
-errorcode NONE

-font FONT

The font of the label text.

A font name, such as TkDefaultFont, or a font description, such as {Helvetica 12 bold}. A family that does not exist falls back to a font of the system.

labelframe with -text Name -width 120 -height 50 and -font TkDefaultFont-font TkDefaultFontlabelframe with -text Name -width 120 -height 50 and -font TkFixedFont-font TkFixedFontlabelframe with -text Name -width 120 -height 50 and -font {Helvetica 16 bold}-font {Helvetica 16 bold}
Each with -text Name -width 120 -height 50.
% labelframe .font -font {Helvetica 12 bold}
> .font cget -font
Helvetica 12 bold
% labelframe .font2 -font {Helvetica big}
expected integer but got "big"
-errorcode TCL VALUE NUMBER

-foreground COLOR

The color of the label text.

The color of the text of -text. -fg is the same option. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.

labelframe with -text Name -width 120 -height 50 and -foreground {#b91c1c}-foreground {#b91c1c}labelframe with -text Name -width 120 -height 50 and -foreground {#2563eb}-foreground {#2563eb}
Each with -text Name -width 120 -height 50.
% labelframe .foreground -foreground {#336699}
> .foreground cget -foreground
#336699
% labelframe .foreground2 -foreground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-labelanchor WORD

The place of the label on the border.

The first letter is the side of the border, and a second letter is the end of that side. For example, nw puts the label at the left end of the top side, and wn puts it at the top end of the left side. n, e, s, and w put the label at the middle of that side.

Values: e, en, es, n, ne, nw, s, se, sw, w, wn, ws.

labelframe with -text Name -width 120 -height 50 and -labelanchor nw-labelanchor nwlabelframe with -text Name -width 120 -height 50 and -labelanchor n-labelanchor nlabelframe with -text Name -width 120 -height 50 and -labelanchor ne-labelanchor nelabelframe with -text Name -width 120 -height 50 and -labelanchor sw-labelanchor swlabelframe with -text Name -width 120 -height 50 and -labelanchor s-labelanchor slabelframe with -text Name -width 120 -height 50 and -labelanchor se-labelanchor se
Each with -text Name -width 120 -height 50.
% labelframe .labelanchor -labelanchor e
> .labelanchor cget -labelanchor
e
% labelframe .labelanchor2 -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 PATHNAME

A widget to show in place of the label text.

The labelframe shows the widget, such as a checkbutton, in the gap of its border in place of -text. The widget must exist when the option is set.

% checkbutton .labelwidgetcb -text Enable
> labelframe .labelwidget -labelwidget .labelwidgetcb
> .labelwidget cget -labelwidget
.labelwidgetcb

ztk stores each value with no check. Tk 8.6.16 gives an error for a widget that does not exist.

-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 theme draws the border, and the CSS of the theme can give a relief its own look with border-style.

Values: flat, groove, raised, ridge, solid, sunken.

labelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief flat-relief flatlabelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief raised-relief raisedlabelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief sunken-relief sunkenlabelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief groove-relief groovelabelframe with -text Name -borderwidth 4 -width 120 -height 50 and -relief ridge-relief ridgelabelframe 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.
% labelframe .relief -relief flat
> .relief cget -relief
flat
% labelframe .relief2 -relief bumpy
bad relief "bumpy": must be flat, groove, raised, ridge, solid, or sunken
-errorcode TCL LOOKUP INDEX relief bumpy

-text TEXT

The text of the label at the border of the labelframe.

The labelframe shows the text in a gap of its border, at the place of -labelanchor. With -labelwidget, the widget replaces the text.

labelframe with -width 120 -height 50 and -text Name-text Namelabelframe with -width 120 -height 50 and -text {Full name}-text {Full name}
Each with -width 120 -height 50.
% labelframe .text -text Options
> .text cget -text
Options

Each string is a valid text.

-background COLOR

The background color of the labelframe.

The color that fills the labelframe. -bg is the same option. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.

labelframe with -text Name -width 120 -height 50 and -background {#fde68a}-background {#fde68a}labelframe with -text Name -width 120 -height 50 and -background {#bfdbfe}-background {#bfdbfe}
Each with -text Name -width 120 -height 50.
% labelframe .background -background {#336699}
> .background cget -background
#336699
% labelframe .background2 -background nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

# Tk 8.6.16 accepts an empty value and draws no background.
% labelframe .background3 -background {}
unknown color name ""
-errorcode TK LOOKUP COLOR {}

-colormap TEXT

The colormap of the labelframe, a feature of X11.

In Tk on X11, new gives the labelframe a colormap of its own. Set it only at the creation of the labelframe. ztk stores the value with no effect.

% labelframe .colormap -colormap new
> .colormap cget -colormap
new
% labelframe .colormap2; .colormap2 configure -colormap new
can't modify -colormap option after widget is created
-errorcode NONE

-container BOOLEAN

Whether the labelframe holds the window of another application, a feature of X11.

In Tk, a container holds an embedded window of another application. Set it only at the creation of the labelframe. ztk stores the value with no effect.

% labelframe .container -container 0
> .container cget -container
0
% labelframe .container2; .container2 configure -container 1
can't modify -container option after widget is created
-errorcode NONE

-cursor CURSOR

The shape of the pointer over the labelframe.

A cursor name of Tk, such as hand2 or xterm. A value that starts with @ names a file. An empty value uses the cursor of the parent.

% labelframe .cursor -cursor hand2
> .cursor cget -cursor
hand2
% labelframe .cursor2 -cursor nocursor
bad cursor spec "nocursor"
-errorcode TK VALUE CURSOR

-height DISTANCE

The height that the labelframe asks for.

With a geometry manager inside the labelframe, such as pack or grid, the size of the children sets the size of the labelframe, and this option has an effect only after pack propagate or grid propagate is off. 0 asks for no height.

labelframe with -text Name -width 120 and -height 30-height 30labelframe with -text Name -width 120 and -height 60-height 60
Each with -text Name -width 120.
% labelframe .height -height 4
> .height cget -height
4
% labelframe .height2 -height x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-highlightbackground COLOR

The color of the focus ring while the labelframe has no focus, in the look of Tk on X11.

The color of the highlight ring of -highlightthickness while the labelframe does not have the focus. ztk stores the value with no effect.

% labelframe .highlightbackground -highlightbackground {#336699}
> .highlightbackground cget -highlightbackground
#336699
% labelframe .highlightbackground2 -highlightbackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-highlightcolor COLOR

The color of the focus ring while the labelframe has the focus, in the look of Tk on X11.

The color of the highlight ring of -highlightthickness while the labelframe has the focus. ztk stores the value with no effect.

% labelframe .highlightcolor -highlightcolor {#336699}
> .highlightcolor cget -highlightcolor
#336699
% labelframe .highlightcolor2 -highlightcolor nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-highlightthickness DISTANCE

The width of the focus ring, in the look of Tk on X11.

The width of the ring around the labelframe that shows the focus. The modern theme stores the value with no effect on the size.

% labelframe .highlightthickness -highlightthickness 4
> .highlightthickness cget -highlightthickness
4
% labelframe .highlightthickness2 -highlightthickness x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-padx DISTANCE

The space between the left and the right sides of the labelframe and its children.

The geometry managers put the children inside this space. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.

% labelframe .padx -padx 4
> .padx cget -padx
4
% labelframe .padx2 -padx x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-pady DISTANCE

The space between the top and the bottom of the labelframe and its children.

The geometry managers put the children inside this space. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.

% labelframe .pady -pady 4
> .pady cget -pady
4
% labelframe .pady2 -pady x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-takefocus TEXT

Whether the Tab key can move the focus to the labelframe.

1 puts the labelframe in the order of the Tab key, and 0 leaves it out. An empty value uses the default rule of Tk for the widget. In Tk the value can also be a script, and its result is the answer. ztk stores each value with no check.

% labelframe .takefocus -takefocus 1
> .takefocus cget -takefocus
1

ztk stores each value of the option with no check.

-visual TEXT

The visual of the labelframe, a feature of X11.

In Tk on X11, the visual sets the color model of the window. Set it only at the creation of the labelframe. ztk stores the value with no effect.

% labelframe .visual -visual {}
> .visual cget -visual
% labelframe .visual2; .visual2 configure -visual best
can't modify -visual option after widget is created
-errorcode NONE

-width DISTANCE

The width that the labelframe asks for.

With a geometry manager inside the labelframe, such as pack or grid, the size of the children sets the size of the labelframe, and this option has an effect only after pack propagate or grid propagate is off. 0 asks for no width.

labelframe with -text Name -height 50 and -width 60-width 60labelframe with -text Name -height 50 and -width 120-width 120
Each with -text Name -height 50.
% labelframe .width -width 4
> .width cget -width
4
% labelframe .width2 -width x
bad screen distance "x"
-errorcode TK VALUE PIXELS

Returns

PATHNAME.

Examples

% labelframe .shipping -text Shipping
> radiobutton .shipping.fast -text Fast -variable speed -value fast
> pack .shipping.fast -anchor w
> winfo children .shipping
.shipping.fast

% labelframe .notes -text Notes -labelanchor n
> .notes cget -labelanchor
n

% winfo class [labelframe .go]
Labelframe

Errors

% labelframe .x -foo 1
unknown option "-foo"
-errorcode TK LOOKUP OPTION -foo

% labelframe .twice
> labelframe .twice
window name "twice" already exists in parent
-errorcode TK VALUE WINDOW EXISTS

# The parent .no does not exist.
% labelframe .no.b
bad window path name ".no"
-errorcode TK LOOKUP WINDOW .no

% labelframe
wrong # args: should be "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