1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/examples/widgets/btn/lv_example_btn_1.py

33 lines
776 B
Python
Raw Normal View History

def event_handler(evt):
code = evt.get_code()
2021-02-08 09:53:03 +01:00
if code == lv.EVENT.CLICKED:
print("Clicked event seen")
elif code == lv.EVENT.VALUE_CHANGED:
print("Value changed seen")
# create a simple button
2021-02-08 09:53:03 +01:00
btn1 = lv.btn(lv.scr_act())
# attach the callback
btn1.add_event_cb(event_handler,lv.EVENT.ALL, None)
btn1.align(lv.ALIGN.CENTER,0,-40)
label=lv.label(btn1)
2021-02-08 09:53:03 +01:00
label.set_text("Button")
# create a toggle button
2021-02-08 09:53:03 +01:00
btn2 = lv.btn(lv.scr_act())
# attach the callback
#btn2.add_event_cb(event_handler,lv.EVENT.VALUE_CHANGED,None)
btn2.add_event_cb(event_handler,lv.EVENT.ALL, None)
btn2.align(lv.ALIGN.CENTER,0,40)
btn2.add_flag(lv.obj.FLAG.CHECKABLE)
btn2.set_height(lv.SIZE.CONTENT)
label=lv.label(btn2)
label.set_text("Toggle")
label.center()