This widget is the ttk version of Section 7, “The Button
widget”. To create a ttk.Button
widget:
w
= ttk.Button(parent
,option
=value
, ...)
Here are the options for the ttk.Button
widget. Compare these to the Tkinter version discussed in Section 7, “The Button
widget”.
Table 35. ttk.Button
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”. |
command
| A function to be called when the button is pressed. |
compound
|
If you provide both
When you provide both |
cursor
| The cursor that will appear when the mouse is over the button; see Section 5.8, “Cursors”. |
image
| An image to appear on the button; see Section 5.9, “Images”. |
style
| The style to be used in rendering this button; see Section 49, “Using and customizing ttk styles”. |
takefocus
|
By default, a ttk.Button 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 button, as a string. |
textvariable
| A variable that controls the text that appears on the button; 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. |
These options of the Tkinter Button
widget are
not supported by the ttk.Button
constructor:
Table 36. Tkinter Button
options not in
ttk.Button
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
For example, if you specify options When the button displays an image but no text, this option is ignored. |
background or bg
|
Configure the background option using a
style. The bg abbreviation is not
supported.
|
bitmap
| Not supported. |
borderwidth or bd
|
Configure the borderwidth option using a
style. The bd abbreviation is not
supported.
|
cursor
| The cursor that will appear when the mouse is over the checkbutton; see Section 5.8, “Cursors”. |
default
| Not supported; see Section 50.2, “ttk style maps: dynamic appearance changes”. |
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 this option using a style. |
height
| Not supported. |
highlightbackground
|
To control the color of the focus highlight when
the button 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. |
justify
|
If the text contains newline ('\n' ) characters, the text will occupy multiple
lines on the button. 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.
|
overrelief
|
Use a style map to control the relief option; see Section 50.2, “ttk style maps: dynamic appearance
changes”.
|
padx
| Not supported. |
pady
| Not supported. |
relief
| Configure this option using a style; see Section 49, “Using and customizing ttk styles”. |
repeatdelay
| Not supported. |
repeatinterval
| Not supported. |
state
| In ttk, there is no option with this name. The state mechanism has been generalized; see Section 50.2, “ttk style maps: dynamic appearance changes”. |
wraplength
|
If you use a style with this option set to some dimensions, the text will be sliced into pieces no longer than
that dimension.
|
Methods on a ttk.Button
include all those
described in Section 46, “Methods common to all ttk widgets”, plus:
.invoke()
Calls the button's command
callback, and
returns what that function returns. Has no effect if the
button is disabled or there is no callback.
The .flash()
method of Tkinter.Button
is not supported by the
ttk.Button
widget.