You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A button has no inherent content so requires child widgets to be added. As a shorthand for a button with a single text label,
433
+
the `text:` option may be used to add a single `label` child, otherwise the `widgets:` key must be used to add other
434
+
widgets inside the button.
435
+
436
+
A button is momentary by default, which has a `pressed` state. If the `checkable` flag is set, it becomes a toggle button, which also has a `checked` state.
437
+
432
438
**Configuration variables:**
433
439
434
-
- **checkable** (*Optional*, boolean): A significant [flag](#lvgl-widget-flags) to make a toggle button (which remains pressed in `checked` state). Defaults to `false`.
440
+
- **checkable** (*Optional*, boolean): A significant [flag](#lvgl-widget-flags) to make a toggle button (which reports its `checked` state). Defaults to `false`.
441
+
- **text** (*Optional*, string): Text to be displayed on the button. This will create and add a single label widget to the button. May not be used
442
+
with the `widgets:` key.
435
443
- Style options from [Style properties](/components/lvgl#lvgl-styling) for the background of the button. Uses the typical background style properties.
436
444
437
445
A notable state is `checked` (boolean) which can have different styles applied.
@@ -445,30 +453,22 @@ A notable state is `checked` (boolean) which can have different styles applied.
445
453
**Example:**
446
454
447
455
```yaml
448
-
# Example widget:
456
+
# Example widget with text:
449
457
- button:
450
-
x: 10
451
-
y: 10
452
-
width: 50
453
-
height: 30
454
458
id: btn_id
459
+
text: "Click me!"
455
460
```
456
461
457
-
To have a button with a text label on it, add a child [`label`](#lvgl-widget-label) widget to it:
462
+
To create an image button, add a child [`image`](#lvgl-widget-image) widget to it:
458
463
459
464
```yaml
460
-
# Example toggle button with text:
465
+
# Example toggle button with image:
461
466
- button:
462
-
x: 10
463
-
y: 10
464
-
width: 70
465
-
height: 30
466
467
id: btn_id
467
468
checkable: true
468
469
widgets:
469
-
- label:
470
-
align: center
471
-
text: "Light"
470
+
- image:
471
+
src: my_image_id
472
472
473
473
# Example trigger:
474
474
- button:
@@ -478,12 +478,37 @@ To have a button with a text label on it, add a child [`label`](#lvgl-widget-lab
478
478
- logger.log:
479
479
format: "Button checked state: %d"
480
480
args: [ x ]
481
+
481
482
```
482
483
483
484
The `button` can be also integrated as a {{< docref "/components/binary_sensor/lvgl" "Binary Sensor" >}} or as a {{< docref "/components/switch/lvgl" "Switch" >}} component.
485
+
> [!NOTE]
486
+
> A binary sensor linked to a button reports its `pressed` state, while a switch linked to a button reports its `checked` state.
484
487
485
488
See [Remote light button](/cookbook/lvgl#lvgl-cookbook-binent) for an example which demonstrates how to use a checkable button to act on a Home Assistant service.
486
489
490
+
**Actions:**
491
+
492
+
- `lvgl.button.update`[action](/automations/actions#actions-action) may be used to update the button styles at runtime. If
493
+
the button has a `text:` option then it may also be updated with this action.
494
+
- **id** (**Required**): The ID or a list of IDs of button widgets to be updated.
495
+
- **text** (*Optional*, string): Update the button's text (only if the button was configured with the `text:` option).
496
+
- Style options from [Style properties](/components/lvgl#lvgl-styling) for the background of the button.
497
+
498
+
> [!NOTE]
499
+
> Where other widgets are added as children, they must be updated directly.
0 commit comments