1def ta_event_cb(e):
2    code = e.get_code()
3    ta = e.get_target()
4    if code == lv.EVENT.CLICKED or code == lv.EVENT.FOCUSED:
5        # Focus on the clicked text area
6        if kb != None:
7            kb.set_textarea(ta)
8
9    elif code == lv.EVENT.READY:
10        print("Ready, current text: " + ta.get_text())
11
12
13# Create the password box
14LV_HOR_RES = lv.scr_act().get_disp().driver.hor_res
15LV_VER_RES = lv.scr_act().get_disp().driver.ver_res
16
17pwd_ta = lv.textarea(lv.scr_act())
18pwd_ta.set_text("")
19pwd_ta.set_password_mode(True)
20pwd_ta.set_one_line(True)
21pwd_ta.set_width(LV_HOR_RES // 2 - 20)
22pwd_ta.set_pos(5, 20)
23pwd_ta.add_event_cb(ta_event_cb, lv.EVENT.ALL, None)
24
25# Create a label and position it above the text box
26pwd_label = lv.label(lv.scr_act())
27pwd_label.set_text("Password:")
28pwd_label.align_to(pwd_ta, lv.ALIGN.OUT_TOP_LEFT, 0, 0)
29
30# Create the one-line mode text area
31text_ta = lv.textarea(lv.scr_act())
32text_ta.set_width(LV_HOR_RES // 2 - 20)
33text_ta.set_one_line(True)
34text_ta.add_event_cb(ta_event_cb, lv.EVENT.ALL, None)
35text_ta.set_password_mode(False)
36
37text_ta.align(lv.ALIGN.TOP_RIGHT, -5, 20)
38
39# Create a label and position it above the text box
40oneline_label = lv.label(lv.scr_act())
41oneline_label.set_text("Text:")
42oneline_label.align_to(text_ta, lv.ALIGN.OUT_TOP_LEFT, 0, 0)
43
44# Create a keyboard
45kb = lv.keyboard(lv.scr_act())
46kb.set_size(LV_HOR_RES, LV_VER_RES // 2)
47
48kb.set_textarea(pwd_ta)  # Focus it on one of the text areas to start
49
50