micropython 日历页
# Initialize import display_driver import lvgl as lv # Create a button with a label # Copyright 2022 NXP # SPDX-License-Identifier: MIT # The auto-generated can only be used on NXP devices def event_handler(evt): code = evt.get_code() if code == lv.EVENT.VALUE_CHANGED: source = evt.get_current_target() date = lv.calendar_date_t() if source.get_pressed_date(date) == lv.RES.OK: calendar.set_today_date(date.year, date.month, date.day) print("Clicked date: %02d.%02d.%02d"%(date.day, date.month, date.year)) calendar = lv.calendar(lv.scr_act()) #calendar.set_size(200, 200) calendar.align(lv.ALIGN.CENTER, 0, 20) calendar.add_event_cb(event_handler, lv.EVENT.ALL, None) calendar.set_today_date(2021, 02, 23) calendar.set_showed_date(2021, 02) # Highlight a few days highlighted_days=[ lv.calendar_date_t({'year':2021, 'month':2, 'day':1}), lv.calendar_date_t({'year':2021, 'month':2, 'day':2}), lv.calendar_date_t({'year':2021, 'month':2, 'day':3}), lv.calendar_date_t({'year':2021, 'month':2, 'day':4}), lv.calendar_date_t({'year':2021, 'month':2, 'day':6}), lv.calendar_date_t({'year':2021, 'month':2, 'day':11}), lv.calendar_date_t({'year':2021, 'month':2, 'day':22}) ] calendar.set_highlighted_dates(highlighted_days, len(highlighted_days)) style_shadow = lv.style_t() style_shadow.init() #style_shadow.set_text_line_space(2) #style_shadow.set_bg_color(lv.color_make(0x56,0x56,0xff)) style_shadow.set_width(lv.scr_act().get_width()) style_shadow.set_height(lv.scr_act().get_height()) calendar.add_style(style_shadow, lv.PART.MAIN|lv.STATE.DEFAULT) calendar.set_pos(0,0) btn=lv.btn(lv.scr_act()) btn.set_pos(lv.scr_act().get_width()-80,lv.scr_act().get_height()-30) btn.set_size(70,20) btn.set_style_pad_all(2,0) btn.set_style_pad_left(5,0) lable1=lv.label(btn) lable1.set_text(lv.SYMBOL.HOME+"HOME") lv.calendar_header_arrow(calendar)
查看效果:日历