1def event_cb(e): 2 obj = e.get_target() 3 id = obj.get_selected_btn() 4 if id == 0: 5 prev = True 6 else: 7 prev = False 8 if id == 6: 9 next = True 10 else: 11 next = False 12 if prev or next: 13 # Find the checked butto 14 for i in range(7): 15 if obj.has_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED): 16 break 17 if prev and i > 1: 18 i-=1 19 elif next and i < 5: 20 i+=1 21 22 obj.set_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED) 23 24# 25# Make a button group 26# 27 28style_bg = lv.style_t() 29style_bg.init() 30style_bg.set_pad_all(0) 31style_bg.set_pad_gap(0) 32style_bg.set_clip_corner(True) 33style_bg.set_radius(lv.RADIUS.CIRCLE) 34style_bg.set_border_width(0) 35 36 37style_btn = lv.style_t() 38style_btn.init() 39style_btn.set_radius(0) 40style_btn.set_border_width(1) 41style_btn.set_border_opa(lv.OPA._50) 42style_btn.set_border_color(lv.palette_main(lv.PALETTE.GREY)) 43style_btn.set_border_side(lv.BORDER_SIDE.INTERNAL) 44style_btn.set_radius(0) 45 46map = [lv.SYMBOL.LEFT,"1","2", "3", "4", "5",lv.SYMBOL.RIGHT, ""] 47 48btnm = lv.btnmatrix(lv.scr_act()) 49btnm.set_map(map) 50btnm.add_style(style_bg, 0) 51btnm.add_style(style_btn, lv.PART.ITEMS) 52btnm.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None) 53btnm.set_size(225, 35) 54 55# Allow selecting on one number at time 56btnm.set_btn_ctrl_all(lv.btnmatrix.CTRL.CHECKABLE) 57btnm.clear_btn_ctrl(0, lv.btnmatrix.CTRL.CHECKABLE) 58btnm.clear_btn_ctrl(6, lv.btnmatrix.CTRL.CHECKABLE) 59 60btnm.set_one_checked(True) 61btnm.set_btn_ctrl(1, lv.btnmatrix.CTRL.CHECKED) 62 63btnm.center() 64 65