TButton
A themed push button. TButton is the ttk (themed) button — it follows the
active theme (Azure light/dark), so prefer it over the classic
Button for a modern look.
Live preview
Try the Theme switcher in the toolbar — this preview restyles live:
Live preview. In the Player's built-in docs viewer (
scriptweaver --help), this rendersTButtonas a live, theme-aware widget you can interact with.
Example
const root = app.TFrame();
root.pack.configure({ expand: true, fill: 'both', padx: 20, pady: 20 });
const btn = root.TButton({
text: 'Click me',
style: 'Accent.TButton',
onClick: () => sw.dialog.alert('Hello from ScriptWeaver!'),
});
btn.pack.configure();
Creating
Create a TButton as a child of any container, using the container's factory
method:
const btn = parent.TButton(options);
parent is any container — app (the main window), a TFrame, a
notebook tab, and so on. The options object may set any of the
options below. Every option can also be read and changed later as a
property:
btn.text = 'Saved'; // set
btn.state = 'disabled';
console.log(btn.text); // get
Options
| Option | Type | Description |
|---|---|---|
text |
string | The button label. |
onClick |
function | Called when the button is activated (mouse click, Space/Enter, or invoke()). Receives the button as its argument. |
style |
string | A ttk style name, e.g. 'Accent.TButton' or 'Toolbutton'. Set back to 'TButton' for the default look. |
state |
string | 'normal' or 'disabled'. |
default |
string | Default-button ring: 'normal', 'active', or 'disabled'. |
image |
Photo |
An icon to show instead of, or alongside, the text. |
compound |
string | How text and image combine: 'text', 'image', 'center', 'left', 'right', 'top', 'bottom'. |
textVariable |
StringVar |
Bind the label to a variable; updating the variable updates the button. |
underline |
number | Index of the character to underline (keyboard mnemonic). |
width |
number | Width in characters. |
justify |
string | Multi-line text alignment: 'left', 'center', 'right'. |
cursor |
string | Mouse cursor while hovering, e.g. 'hand2'. |
takeFocus |
boolean | Whether the button accepts keyboard focus via Tab. |
Events
onClick covers the common case. For anything else — hover, right-click, focus
changes — use bind():
btn.bind('<Enter>', () => (btn.style = 'Accent.TButton'));
btn.bind('<Leave>', () => (btn.style = 'TButton'));
Methods
| Method | Description |
|---|---|
invoke() |
Programmatically activate the button (runs its onClick). Returns the handler's result. |
TButton also inherits the common widget methods — layout (pack, grid,
place), bind(), focus(), destroy(), and the wm /
winfo helpers. See Widget basics.
See also
Button— the classic (non-themed) button- Layout — placing the button in a window
- Events & binding — handling other interactions