RadioButton
A classic radio button — one of a set of mutually exclusive choices. For a radio
button that follows the active theme, prefer TRadioButton;
reach for RadioButton only when you want the classic Tk look or a classic-only
option such as selectColor or background.
Radio buttons in a group share one StringVar (or
IntVar); each button writes its own value into the variable when chosen, so
reading the variable tells you which one is selected.
Example
const size = new StringVar();
size.value = 'm'; // medium starts selected
for (const [text, value] of [
['Small', 's'],
['Medium', 'm'],
['Large', 'l'],
]) {
app.RadioButton({ text, value, variable: size }).pack.configure({ anchor: 'w' });
}
console.log(size.value); // 's' / 'm' / 'l' — whichever is chosen
Options
| Option | Type | Description |
|---|---|---|
text |
string | The label beside the button. |
variable |
a *Var |
The shared group variable. |
value |
any | The value written to variable when this button is chosen. |
onClick |
function | Called when this button is selected. |
state |
string | 'normal', 'active', or 'disabled'. |
image |
Photo |
Optional image. |
selectColor |
string | Colour of the indicator when selected. |
background / foreground |
string | Button and label colours. |
textVariable |
StringVar |
Bind the label text. |
Methods
| Method | Description |
|---|---|
invoke() |
Select this button programmatically (runs onClick). |
Plus the inherited widget methods — see Widget basics.
See also
TRadioButton— the themed radio button (preferred)- Variables & reactivity — sharing a group variable
CheckButton