Lists, menus, dialogs · Round 1.28" touch watch
Widget gallery 6 - List, menu with sub-pages, message box, window
You’ll learn: list, menu, window, msgbox
Board: Waveshare ESP32-S3-Touch-LCD-1.28 (ESP32-S3R2). Part of the kit’s Widget gallery. Needs the board’s LVGL firmware: flash it from the notebook’s Flash button, then press Open in Full IDE.
# Widget gallery 6 - List, menu with sub-pages, message box, window
import lvgl as lv
import display
display.init() # start the display and touch (does nothing if already on)
BG = 0x05110A
scr = lv.screen_active() # the screen LVGL is showing
scr.clean() # remove what the last program drew
scr.set_style_bg_color(lv.color_hex(BG), 0)
scr.remove_flag(lv.obj.FLAG.SCROLLABLE)
tv = lv.tileview(scr)
tv.set_style_bg_opa(lv.OPA.TRANSP, 0)
# 1. List with icons
t = tv.add_tile(0, 0, lv.DIR.RIGHT)
lst = lv.list(t)
lst.set_size(170, 170)
lst.center()
lst.add_text("Apps")
for sym, name in ((lv.SYMBOL.AUDIO, "Music"), (lv.SYMBOL.GPS, "Maps"), (lv.SYMBOL.BELL, "Alarms"),
(lv.SYMBOL.WIFI, "Wi-Fi"), (lv.SYMBOL.BLUETOOTH, "Bluetooth"), (lv.SYMBOL.SETTINGS, "Settings")):
b = lst.add_button(sym, name)
b.add_event_cb(lambda e, n=name: print("open", n), lv.EVENT.CLICKED, None)
# 2. Menu with a sub page (back button is automatic)
t = tv.add_tile(1, 0, lv.DIR.LEFT | lv.DIR.RIGHT)
menu = lv.menu(t)
menu.set_size(180, 170)
menu.center()
main = lv.menu_page(menu, None)
sub = lv.menu_page(menu, "Display")
for txt in ("Brightness", "Timeout", "Always on"):
c = lv.menu_cont(sub)
lv.label(c).set_text(txt)
for txt, target in (("Display", sub), ("Sound", None), ("About", None)):
c = lv.menu_cont(main)
lv.label(c).set_text(txt + (" " + lv.SYMBOL.RIGHT if target else ""))
if target:
menu.set_load_page_event(c, target)
menu.set_page(main)
# 3. Message box + window
t = tv.add_tile(2, 0, lv.DIR.LEFT)
win = lv.win(t)
win.set_size(170, 150)
win.center()
win.add_title("Window")
content = win.get_content()
lv.label(content).set_text("A window has a\nheader and content.")
btn = lv.button(content)
btn.align(lv.ALIGN.BOTTOM_MID, 0, 0)
lv.label(btn).set_text("Show msgbox")
def show_msg(e):
mb = lv.msgbox(None) # None = modal on top of everything
mb.add_title("Hello")
mb.add_text("This is lv.msgbox")
mb.add_close_button()
mb.set_width(180)
btn.add_event_cb(show_msg, lv.EVENT.CLICKED, None)
print("Swipe: list, menu (tap Display), window + message box.")
Comments