lv_example_event_3.py 728 B

123456789101112131415161718192021222324252627282930313233
  1. def event_cb(e):
  2. # The original target of the event. Can be the buttons or the container
  3. target = e.get_target()
  4. # print(type(target))
  5. # If container was clicked do nothing
  6. if type(target) != type(lv.btn()):
  7. return
  8. # Make the clicked buttons red
  9. target.set_style_bg_color(lv.palette_main(lv.PALETTE.RED), 0)
  10. #
  11. # Demonstrate event bubbling
  12. #
  13. cont = lv.obj(lv.scr_act())
  14. cont.set_size(320, 200)
  15. cont.center()
  16. cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
  17. for i in range(30):
  18. btn = lv.btn(cont)
  19. btn.set_size(80, 50)
  20. btn.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
  21. label = lv.label(btn)
  22. label.set_text(str(i))
  23. label.center()
  24. cont.add_event_cb(event_cb, lv.EVENT.CLICKED, None)