[Tkinter Series 17/45] ttk component library LabelFrame, Menubutton

35. ttk.LabelFrame

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

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

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

Options include:

Table 46. ttk.LabelFrameoptions

borderwidth Use This option sets the border width around the widget to the given size. This option can also be configured using styles.
class_ You can provide the widget class name when creating this widget. This name can be used to customize the widget’s appearance; see Section 27, “Appearance Standardization”. 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 (empty string) specifies that the cursor is inherited from the parent widget.
height This option can be set to a size to specify the height of the frame. This option is ignored if the .grid_propagate(0) method is not called; see Section 4.2, “Other Grid Management Methods”.
labelanchor

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

labelwidget

You can use any widget as a label in ttk instead of text label .LabelFrame. Create some widget w but do not register it using the .grid() method. Then create LabelFrame with . If you specify both this option and the option, the latter will be ignored. labelwidget=wtext

For example, if you don’t like the rather small and simple default font used for labels, you can use this option to display the Label widget with a font and additional appearance of your choice.

padding To add extra white space around the content of this widget, set this option to Dimension. This option can also be specified via styles.
relief Use this option to specify a 3-D border style; see Section 5.6, “Relief Style”. You need to specify a non-zero value for borderwidth to display this effect. This option can also be specified via styles.
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 accessed during focus traversal; see Section 53, “Focus: Routing Keyboard Input”. Specify takefocus=True whether you want access to accept focus; specify takefocus=False whether the widget does not accept focus.

The default value is an empty string; by default, the ttk.Label widget does not receive focus.

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

You can request that a letter in a text string be underlined by setting this option to the position of that letter. For example, if you specify text='Panic' and underline=2, the underline will appear under 'n'.

Using this option does not change any functionality. If you want your application to react to the Q key or some variation (such as control-shift-Q), you need to set up the binding using the event system.

width This option can be set to a size to specify the width of the frame. This option is ignored if the .grid_propagate(0) method is not called; 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 not available in ttkTkinter LabelFrame options .LabelFrame

background or bg background Use style configuration options; see Section 47, “Customizing and Creating ttk Themes and Styles”. bg does not support abbreviations.
highlightbackground To control the color of the focus highlight when there is no focusLabelFrame, use stylemaps to control the option highlightcolor; see Section 50.2, “TTK Stylemaps: Dynamic Appearance Changes”.
highlightcolor You can specify this by setting this option in the style Default focus highlight color. You can also control focus highlight color using style maps.
highlightthickness Configure this option using styles. This option may not be available for all themes.

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

36. ttk.Menubutton

The small Menubutton widget is part of an always-visible drop-down menu. It is always used in conjunction with a widget, Menu, which controls what is displayed when the user clicks Menubutton.

There is no ttk version Menu for this widget. Use regular Tkinter widgets as described in Section 15, “Widgets”. Menu

To create a new ttk.Menubutton widget as a child of a widget parent , use the following constructor:

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

Options include:

Table 48. ttk.MenubuttonOptions

class_ Widget class name. This can be specified when the widget is created, but cannot be changed later. See Section 27, “Standardized Appearance” for a description of widget classes.
compound

If both the image and text options are provided, the compound option specifies the position of the image relative to the text. The value can be tk.TOP (image above text), tk.BOTTOM (image below text), tk.LEFT (image below text) image to the left) or tk.RIGHT (image to the right of the text).

When you provide the image and text options without specifying the compound option, the image will be displayed but the text will not be displayed.

cursor When the mouse is hovering over the button The cursor that appears; see Section 5.8 “Cursors”.
direction

This option specifies where the drop-down menu appears relative to the menu button.

above The menu will appear directly above the menu button.
below The menu will appear directly below the menu button.
flush The menu will appear above the menu button so that the menu The northwest corner coincides with the northwest corner of the menu button.
left The menu will appear to the left of the menu button.
right The menu will appear to the right of the menu button.
image The image that appears on the menu button ;See Section 5.9 “Images”.
menu Related Menu small part. See Section 15, “Menu Widgets” for the process used to establish this interconnection.
style The style to use when rendering this menu button; see Section 49, “Using and Customizing ttk Styles”.
takefocus By default, focus traversal will contain a < em>ttk ;.MenubuttonSee Section 53, “Focus: Routing Keyboard Input”. To remove a widget from focus traversal, use takefocus=False.
text The text displayed on the menu button, as a string .
textvariable Variable that controls the text displayed on the menu button; please See Section 52, “Control Variables: Values Behind Widgets”.
underline If this option has a non-negative valuen , then an underline will appear under the character at position n.
width If the label is text, this option specifies the button on The absolute width of the text area in characters; the actual width is this number multiplied by the average width of characters in the current font. For image tags, this option is ignored. This option can also be configured per style.

ttk does not support the following options for Tkinter buttons described in Section 16, “Widgets”: MenubuttonMenubutton.Menubutton

Table 49. Tkinter not available in ttkTkinter Menubutton options .Menubutton

activebackground Use Stylemaps to control the background option; see Section 50.2, “ttk Stylemaps: Dynamic Appearance Changes”.
activeforeground Use style maps to control foreground options.
anchor Configure this option using a style; see Section 49, “Using and Customizing ttk Styles”. Use this option to specify the position of text width when this option allocates additional horizontal space.
bitmap Not supported.
borderwidth or bd borderwidth uses style configuration options. bd does not support abbreviations.
buttonbackground Not supported.
buttoncursor Not supported.
buttondownrelief Not supported.
buttonup Not supported.
disabledforeground Use stylemaps as the foreground option; see Section 50.2, “ttk Stylemaps: Dynamic Appearance Changes”.
font Configure this option using styles.
foreground or fg foreground uses style configuration options.
height Not supported.
highlightbackground To control the color of the focus highlight when the menubutton has no focus, you can use a style map to control the option highlightcolor; see Section 50.2, “ttk Style Map: Dynamic Appearance Changes”.
highlightcolor You can specify the default focus highlight color by setting this option in the style. You can also control focus highlight color using style maps.
highlightthickness Configure this option using styles.
justify If text contains newline ( '\
'
) characters, the text will occupy multiple lines on the menu button. The justify option controls how each line is positioned horizontally. Configure this option using a style; the value can be tk.LEFT, tk.CENTER, or for left-aligned, centered, or right-aligned lines. tk.RIGHT
padx Not supported.
pady Not supported.
relief Configure this option using a style; see Section 49, “Using and Customizing ttk Styles”.
wraplength If you use a style that sets this option to a certain dimension, the text will be cut into pieces that are no longer than that dimension.