Next / Previous / Contents

36. ttk.Menubutton

A Menubutton widget is the part of a drop-down menu that is always visible. It is always used in combination with a Menu widget that controls what appears when the user clicks on the Menubutton.

There is no ttk version of the Menu widget. Use the regular Tkinter widget described in Section 15, “The Menu widget”.

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

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

Options include:

Table 48. ttk.Menubutton options

class_ The widget class name. This may be specified when the widget is created, but cannot be changed later. For an explanation of widget classes, see Section 27, “Standardizing appearance”.
compound

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

When you provide both image and text options but don't specify a compound option, the image will appear and the text will not.

cursor The cursor that will appear when the mouse is over the button; see Section 5.8, “Cursors”.
direction

This option specifies the position where the drop-down menu appears, relative to the menubutton.

above The menu will appear just above the menubutton.
below The menu will appear just below the menubutton.
flush The menu will appear over the menubutton, so that the menu's northwest corner coincides with the menubutton's northwest corner.
left The menu will appear just to the left of the menubutton.
right The menu will appear just to the right of the menubutton.

image An image to appear on the menubutton; see Section 5.9, “Images”.
menu The related Menu widget. See Section 15, “The Menu widget” for the procedure used to establish this mutual connection.
style The style to be used in rendering this menubutton; see Section 49, “Using and customizing ttk styles”.
takefocus By default, a ttk.Menubutton will be included in focus traversal; see Section 53, “Focus: routing keyboard input”. To remove the widget from focus traversal, use takefocus=False.
text The text to appear on the menubutton, as a string.
textvariable A variable that controls the text that appears on the menubutton; see Section 52, “Control variables: the values behind the widgets”.
underline If this option has a nonnegative value n, an underline will appear under the character at position n.
width If the label is text, this option specifies the absolute width of the text area on the button, as a number of characters; the actual width is that number multiplied by the average width of a character in the current font. For image labels, this option is ignored. The option may also be configured in a style.

The following options of the Tkinter Menubutton button, described in Section 16, “The Menubutton widget”, are not supported by ttk.Menubutton:

Table 49. Tkinter Menubutton options not in ttk.Menubutton

activebackground Use a style map to control the background option; see Section 50.2, “ttk style maps: dynamic appearance changes”.
activeforeground Use a style map to control the foreground option.
anchor Configure this option using a style; see Section 49, “Using and customizing ttk styles”. Use this option to specify the position of the text when the width option allocates extra horizontal space.
bitmap Not supported.
borderwidth or bd Configure the borderwidth option using a style. The bd abbreviation is not supported.
buttonbackground Not supported.
buttoncursor Not supported.
buttondownrelief Not supported.
buttonup Not supported.
disabledforeground Use a style map for the foreground option; see Section 50.2, “ttk style maps: dynamic appearance changes”.
font Configure this option using a style.
foreground or fg Configure the foreground option using a style.
height Not supported.
highlightbackground To control the color of the focus highlight when the menubutton 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.
justify If the text contains newline ('\n') characters, the text will occupy multiple lines on the menubutton. The justify option controls how each line is positioned horizontally. Configure this option using a style; values may be tk.LEFT, tk.CENTER, or tk.RIGHT for lines that are left-aligned, centered, or right-aligned, respectively.
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 with this option set to some dimension, the text will be sliced into pieces no longer than that dimension.