Next / Previous / Contents

35. ttk.LabelFrame

This is the ttk version of the basic Tkinter widget described in Section 13, “The LabelFrame widget”.

To create a new ttk.LabelFrame widget as a child of a given parent widget:

    w = ttk.LabelFrame(parent, option=value, ...)

Options include:

Table 46. ttk.LabelFrame options

borderwidth Use this option to set the width of the border around the widget to a given dimension. This option may also be configured using a style.
class_ You may provide a widget class name when you create this widget. This name may be used to customize the widget's appearance; see Section 27, “Standardizing appearance”. Once the widget is created, the widget class name cannot be changed.
cursor Use this option to specify the appearance of the mouse cursor when it is over the widget; see Section 5.8, “Cursors”. The default value (an empty string) specifies that the cursor is inherited from the parent widget.
height This option can be set to some dimension to specify the height of the frame. If you don't call the .grid_propagate(0) method, this option will be ignored; see Section 4.2, “Other grid management methods”.
labelanchor

Use this option to specify the position of the label on the widget's border. The default position is 'nw', which places the label at the left end of the top border. For the nine possible label positions, refer to Section 13, “The LabelFrame widget”.

labelwidget

Instead of a text label, you can use any widget as the label in a ttk.LabelFrame. Create some widget w but do not register it with the .grid() method. Then create the LabelFrame with labelwidget=w. If you specify this option as well as the text option, the latter is ignored.

For example, if you don't like the rather small and plain default font used for the label, you can use this option to display a Label widget with the font and other appearance of your choice.

padding To add extra clear area around the contents of this widget, set this option to a dimension. This option may also be specified by a style.
relief Use this option to specify a 3-d border style; see Section 5.6, “Relief styles”. You will need to specify a nonzero borderwidth for this effect to appear. This option may also be specified by a style.
style Use this option to specify a custom widget style name; see Section 47, “Customizing and creating ttk themes and styles”.
takefocus

Use this option to specify whether the widget is visited during focus traversal; see Section 53, “Focus: routing keyboard input”. Specify takefocus=True if you want the visit to accept focus; specify takefocus=False if the widget is not to accept focus.

The default value is an empty string; by default, ttk.Label widgets do not get focus.

text The value of this option is a string that will appear as part of the border.
underline

You can request that one of the letters in the text string be underline by setting this option to the position of that letter. For example, if you specified text='Panic' and underline=2, an underline would appear under the 'n'.

Using this option doesn't change anything functionally. If you want the application to react to the Q key or some variation like control-shift-Q, you'll need to set up the bindings using the event system.

width This option can be set to some dimension to specify the width of the frame. If you don't call the .grid_propagate(0) method, this option will be ignored; see Section 4.2, “Other grid management methods”.

The following options available for the Tkinter LabelFrame widget are not available as constructor arguments.

Table 47. Tkinter LabelFrame options not in ttk.LabelFrame

background or bg Configure the background option using a style; see Section 47, “Customizing and creating ttk themes and styles”. The bg abbreviation is not supported.
highlightbackground To control the color of the focus highlight when the LabelFrame does not have focus, use a style map to control the highlightcolor option; see Section 50.2, “ttk style maps: dynamic appearance changes”.
highlightcolor You may specify the default focus highlight color by setting this option in a style. You may also control the focus highlight color using a style map.
highlightthickness Configure this option using a style. This option may not work in all themes.

The ttk.LabelFrame widget supports all the methods described in Section 46, “Methods common to all ttk widgets”.