1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/examples/get_started/lv_example_get_started_1.py
Amir Gonnen c751c11a87
fix(examples) remove cast in MP scripts (#2354)
After https://github.com/lvgl/lv_binding_micropython/pull/161 merged, it is no longer needed to cast the result of 'e.get_target()'

Also, additional small fixes to allow CI improvements
2021-07-07 17:04:46 +02:00

30 lines
1.1 KiB
Python

class CounterBtn():
def __init__(self):
self.cnt = 0
#
# Create a button with a label and react on click event.
#
btn = lv.btn(lv.scr_act()) # Add a button the current screen
btn.set_pos(10, 10) # Set its position
btn.set_size(120, 50) # Set its size
btn.align(lv.ALIGN.CENTER,0,0)
btn.add_event_cb(self.btn_event_cb, lv.EVENT.ALL, None) # Assign a callback to the button
label = lv.label(btn) # Add a label to the button
label.set_text("Button") # Set the labels text
label.center()
def btn_event_cb(self,evt):
code = evt.get_code()
btn = evt.get_target()
if code == lv.EVENT.CLICKED:
self.cnt += 1
# Get the first child of the button which is the label and change its text
label = btn.get_child(0)
label.set_text("Button: " + str(self.cnt))
counterBtn = CounterBtn()