1def event_handler(e): 2 code = e.get_code() 3 obj = e.get_target() 4 if code == lv.EVENT.VALUE_CHANGED: 5 if obj.has_state(lv.STATE.CHECKED): 6 print("State: on") 7 else: 8 print("State: off") 9 10 11lv.scr_act().set_flex_flow(lv.FLEX_FLOW.COLUMN) 12lv.scr_act().set_flex_align(lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER) 13 14sw = lv.switch(lv.scr_act()) 15sw.add_event_cb(event_handler,lv.EVENT.ALL, None) 16 17sw = lv.switch(lv.scr_act()) 18sw.add_state(lv.STATE.CHECKED) 19sw.add_event_cb(event_handler, lv.EVENT.ALL, None) 20 21sw = lv.switch(lv.scr_act()) 22sw.add_state(lv.STATE.DISABLED) 23sw.add_event_cb(event_handler, lv.EVENT.ALL, None) 24 25sw = lv.switch(lv.scr_act()) 26sw.add_state(lv.STATE.CHECKED | lv.STATE.DISABLED) 27sw.add_event_cb(event_handler, lv.EVENT.ALL, None) 28 29