Button
A classic push button. For a button that follows the active theme, prefer
TButton; reach for Button only when you want the classic Tk
look or a classic-only option such as relief or background.
Example
const b = app.Button({
text: 'Press',
onClick: () => console.log('pressed'),
});
b.pack.configure({ padx: 20, pady: 20 });
Options
| Option | Type | Description |
|---|---|---|
text |
string | The button label. |
onClick |
function | Called when the button is activated. |
state |
string | 'normal', 'active', or 'disabled'. |
image |
Photo |
Icon instead of, or with, the text. |
compound |
string | Text / image placement: 'left', 'right', 'top', 'bottom', 'center'. |
font |
string | Label font, e.g. '{Segoe UI} 11'. |
background / foreground |
string | Button and text colours. |
relief |
string | Border style: 'raised', 'flat', 'sunken', 'groove', 'ridge'. |
width |
number | Width in characters. |
textVariable |
StringVar |
Bind the label to a variable. |
underline |
number | Index of the mnemonic character. |
Methods
| Method | Description |
|---|---|
invoke() |
Activate the button programmatically (runs onClick). |
flash() |
Briefly flash the button. |
Plus the inherited widget methods — see Widget basics.
See also
TButton— the themed button (preferred)- Events & binding