To create a pushbutton in a top-level window or frame
named
:master
w
= Button (master
,option
=value
, ... )
The constructor returns the new button object. Its options include:
activebackground | Background color when the button is under the cursor. |
activeforeground | Foreground color when the button is under the cursor. |
anchor | Where the text is positioned on the button.
See Section 4.5, “Anchors”. For example,
anchor=NE would position the
text at the top right corner of the button. |
bd or
borderwidth | Border width in pixels. Default is 2. |
bg or
background | Normal background color. |
bitmap | Name of one of the standard bitmaps to display on the button (instead of text). |
command | Function or method to be called when the button is clicked. |
cursor | Selects the cursor to be shown when the mouse is over the button. |
default | NORMAL is the default;
use DISABLED if the button
is to be initially disabled (grayed out, unresponsive to
mouse clicks). |
disabledforeground | Foreground color used when the button is disabled. |
fg or
foreground | Normal foreground (text) color. |
font | Text font to be used for the button's label. |
height | Height of the button in text lines (for textual buttons) or pixels (for images). |
highlightbackground | Color of the focus highlight when the widget does not have focus. |
highlightcolor | The color of the focus highlight when the widget has focus. |
highlightthickness | Thickness of the focus highlight. |
image | Image to be displayed on the button (instead of text). |
justify | How to show multiple text lines:
LEFT to left-justify each
line; CENTER to center them;
or RIGHT to
right-justify. |
padx | Additional padding left and right of the text. See Section 4.1, “Dimensions” for the possible values for padding. |
pady | Additional padding above and below the text. |
relief | Specifies the relief type for the button
(see Section 4.6, “Relief styles”). The default
relief is RAISED . |
state | Set this option to
DISABLED to gray out the
button and make it unresponsive. Has the value
ACTIVE when the mouse is
over it. Default is
NORMAL . |
takefocus | Normally, keyboard focus does visit buttons
(see Section 23, “Focus: routing keyboard input”), and a
space character acts as the same
as a mouse click, “pushing” the button.
You can set the takefocus
option to zero to prevent focus from visiting the
button. |
text | Text displayed on the button. Use internal newlines to display multiple text lines. |
textvariable | An instance of
StringVar() that is
associated with the text on this button. If the
variable is changed, the new value will be
displayed on the button. See Section 22, “Control variables: the values behind the widgets”. |
underline | Default is -1 , meaning
that no character of the text on the button will be
underlined. If nonnegative, the corresponding text
character will be underlined. For example,
underline=1 would underline
the second character of the button's text. |
width | Width of the button in letters (if displaying text) or pixels (if displaying an image). |
wraplength | If this value is set to a positive number, the text lines will be wrapped to fit within this length. For possible values, see Section 4.1, “Dimensions”. |
Methods on Button
objects:
.flash()
Causes the button to flash several times between active and normal colors. Leaves the button in the state it was in originally. Ignored if the button is disabled.
.invoke()
Calls the button's callback, and returns what that function returns. Has no effect if the button is disabled or there is no callback.