mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
33 lines
810 B
Python
33 lines
810 B
Python
def event_handler(evt):
|
|
code = evt.get_code()
|
|
|
|
if code == lv.EVENT.CLICKED:
|
|
print("Clicked event seen")
|
|
elif code == lv.EVENT.VALUE_CHANGED:
|
|
print("Value changed seen")
|
|
|
|
# create a simple button
|
|
button1 = lv.button(lv.screen_active())
|
|
|
|
# attach the callback
|
|
button1.add_event(event_handler,lv.EVENT.ALL, None)
|
|
|
|
button1.align(lv.ALIGN.CENTER,0,-40)
|
|
label=lv.label(button1)
|
|
label.set_text("Button")
|
|
|
|
# create a toggle button
|
|
button2 = lv.button(lv.screen_active())
|
|
|
|
# attach the callback
|
|
#button2.add_event(event_handler,lv.EVENT.VALUE_CHANGED,None)
|
|
button2.add_event(event_handler,lv.EVENT.ALL, None)
|
|
|
|
button2.align(lv.ALIGN.CENTER,0,40)
|
|
button2.add_flag(lv.obj.FLAG.CHECKABLE)
|
|
button2.set_height(lv.SIZE_CONTENT)
|
|
|
|
label=lv.label(button2)
|
|
label.set_text("Toggle")
|
|
label.center()
|