`drawablebutton()` creates a button that displays an image.
Creates a drawablebutton object.
| Item | Description |
|---|---|
| Syntax | `drawablebutton()` |
| Arguments | none |
| Returns | drawablebutton object |
Example:
btn = drawablebutton().image(24, 24, 'icons/start.svg');
Properties are read-only. Use methods to change GUI object state.
| Property | Type | Description |
|---|---|---|
| `position_x` | number | Current x position. |
| `position_y` | number | Current y position. |
| `size_width` | number | Current width. |
| `size_height` | number | Current height. |
| `visible` | boolean | Current visible state. |
| `enabled` | boolean | Current enabled state. |
Returns a display string for the object.
| Item | Description |
|---|---|
| Syntax | `value.to_string()` |
| Arguments | none |
| Returns | string |
Example:
text = value.to_string();
`clone()` is not supported for `drawablebutton`.
Most visible GUI controls support these methods.
Sets the component position in pixels.
| Item | Description |
|---|---|
| Syntax | `component.position(x, y)` |
| Arguments | `x`: x position; `y`: y position |
| Returns | component object |
Example:
label().position(20, 10);
Sets the component size in pixels. Width and height are clamped to at least `1`.
Some container objects, such as `panel()` and `group()`, use `size(-1, -1)` as a special fit-parent mode.
| Item | Description |
|---|---|
| Syntax | `component.size(width, height)` |
| Arguments | `width`: width in pixels; `height`: height in pixels |
| Returns | component object |
Example:
textinput().size(220, 26);
Shows or hides the component.
| Item | Description |
|---|---|
| Syntax | `component.visible(enabled)` |
| Arguments | `enabled`: boolean |
| Returns | component object |
Example:
status.visible(false);
Enables or disables user interaction with the component.
| Item | Description |
|---|---|
| Syntax | `component.enabled(enabled)` |
| Arguments | `enabled`: boolean |
| Returns | component object |
Example:
run_button.enabled(false);
Sets the button image and preferred image size.
| Item | Description |
|---|---|
| Syntax | `drawablebutton.image(width, height, filePath)` |
| Arguments | `width`: preferred image width; `height`: preferred image height; `filePath`: image file path |
| Returns | drawablebutton object |
Example:
btn = drawablebutton().image(24, 24, 'icons/start.svg');
Sets a callback called when the button is clicked.
| Item | Description |
|---|---|
| Syntax | `drawablebutton.on_click(callback)` |
| Arguments | `callback`: callable with no arguments |
| Returns | drawablebutton object |
Example:
function start_clicked() { print('start'); } btn = drawablebutton().on_click(start_clicked);
Simulates a button click and calls the click callback when possible.
| Item | Description |
|---|---|
| Syntax | `drawablebutton.click()` |
| Arguments | none |
| Returns | drawablebutton object |
Example:
btn.click();
function start_clicked() { print('start'); } btn = drawablebutton() .position(20, 20) .size(34, 34) .image(24, 24, 'icons/start.svg') .on_click(start_clicked); window().title('Image Button').size(120, 100).add(btn).show();
Previous: textbutton
Next: togglebutton