2023-02-20 20:50:58 +01:00
|
|
|
def slider_event_cb(e):
|
|
|
|
slider = e.get_target_obj()
|
2022-11-22 14:37:51 +01:00
|
|
|
|
|
|
|
# Refresh the text
|
|
|
|
label.set_text(str(slider.get_value()))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Create a slider and write its value on a label.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Create a slider in the center of the display
|
2023-10-12 20:37:27 +02:00
|
|
|
slider = lv.slider(lv.screen_active())
|
2022-11-22 14:37:51 +01:00
|
|
|
slider.set_width(200) # Set the width
|
|
|
|
slider.center() # Align to the center of the parent (screen)
|
2023-02-20 20:50:58 +01:00
|
|
|
slider.add_event(slider_event_cb, lv.EVENT.VALUE_CHANGED, None) # Assign an event function
|
2022-11-22 14:37:51 +01:00
|
|
|
|
|
|
|
# Create a label above the slider
|
2023-10-12 20:37:27 +02:00
|
|
|
label = lv.label(lv.screen_active())
|
2022-11-22 14:37:51 +01:00
|
|
|
label.set_text("0")
|
|
|
|
label.align_to(slider, lv.ALIGN.OUT_TOP_MID, 0, -15) # Align below the slider
|
|
|
|
|
|
|
|
|