M5Calendar
M5Calendar is a widget that can be used to create a calendar in the user interface. It can be used to display and select dates.
UiFlow2 Example
event calendar
Open the calendar_core2_example.m5f2 project in UiFlow2.
This example creates a calendar that triggers an event when the date is changed.
UiFlow2 Code Block:
Example output:
None
MicroPython Example
event calendar
This example creates a calendar that triggers an event when the date is changed.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8import m5ui 9import lvgl as lv 10 11 12page0 = None 13calendar0 = None 14 15 16year = None 17month = None 18day = None 19 20 21def calendar0_value_changed_event(date): 22 global page0, calendar0, year, month, day 23 year = date.year 24 month = date.month 25 day = date.day 26 calendar0.set_today_date(year, month, day) 27 print((str("Today is:") + str((str(year) + str((str(month) + str(day))))))) 28 29 30def calendar0_event_handler(event_struct): 31 global page0, calendar0, year, month, day 32 event = event_struct.code 33 if event == lv.EVENT.VALUE_CHANGED: 34 date = lv.calendar_date_t() 35 if calendar0.get_pressed_date(date) == lv.RESULT.OK: 36 calendar0_value_changed_event(date) 37 return 38 39 40def setup(): 41 global page0, calendar0, year, month, day 42 43 M5.begin() 44 Widgets.setRotation(1) 45 m5ui.init() 46 page0 = m5ui.M5Page(bg_c=0xFFFFFF) 47 calendar0 = m5ui.M5Calendar( 48 x=0, 49 y=0, 50 w=320, 51 h=240, 52 style="arrow", 53 today_date=[2025, 8, 7], 54 show_month=[2025, 8], 55 parent=page0, 56 ) 57 58 calendar0.add_event_cb(calendar0_event_handler, lv.EVENT.ALL, None) 59 60 page0.screen_load() 61 62 63def loop(): 64 global page0, calendar0, year, month, day 65 M5.update() 66 67 68if __name__ == "__main__": 69 try: 70 setup() 71 while True: 72 loop() 73 except (Exception, KeyboardInterrupt) as e: 74 try: 75 m5ui.deinit() 76 from utility import print_error_msg 77 78 print_error_msg(e) 79 except ImportError: 80 print("please update to latest firmware")
Example output:
None
API
M5Calendar
- class m5ui.calendar.M5Calendar(*args, **kwargs)
Bases:
calendarCreate a calendar object.
- Parameters:
x (int) – The x position of the calendar.
y (int) – The y position of the calendar.
w (int) – The width of the calendar.
h (int) – The height of the calendar.
style (str) – The style of the calendar, can be “arrow” or “dropdown” and None.
today_date (list) – The date to highlight as today in the format [year, month, day].
show_month (list) – The month to show in the format [year, month].
parent (lv.obj) – The parent object to attach the calendar to. If not specified, the calendar will be attached to the default screen.
MicroPython Code Block:
from m5ui import M5Calendar import lvgl as lv m5ui.init() calendar_0 = M5Calendar(x=0, y=0, w=200, h=200, style=None, today_date=[2024, 1, 1], show_month=[2024, 1], parent=page0)
- set_month_shown(year, month)
Set the month and year shown in the calendar.
UiFlow2 Code Block:

MicroPython Code Block:
calendar_0.set_month_shown(2023, 3)
- set_pos(x, y)
Set the position of the calendar.
UiFlow2 Code Block:

MicroPython Code Block:
calendar_0.set_pos(100, 100)
- set_x(x)
Set the x-coordinate of the calendar.
- Parameters:
x (int) – The x-coordinate of the calendar.
UiFlow2 Code Block:

MicroPython Code Block:
calendar_0.set_x(100)
- set_y(y)
Set the y-coordinate of the calendar.
- Parameters:
y (int) – The y-coordinate of the calendar.
UiFlow2 Code Block:

MicroPython Code Block:
calendar_0.set_y(100)
- set_size(width, height)
Set the size of the calendar.
UiFlow2 Code Block:

MicroPython Code Block:
calendar_0.set_size(100, 50)
- align_to(obj, align, x, y)
Align the calendar to another object.
- Parameters:
UiFlow2 Code Block:

MicroPython Code Block:
calendar_0.align_to(page_0, lv.ALIGN.CENTER, 0, 0)
- add_event_cb(handler, event, user_data)
Add an event callback to the calendar. The callback will be called when the specified event occurs.
- Parameters:
handler (function) – The callback function to call.
event (int) – The event to listen for.
user_data (Any) – Optional user data to pass to the callback.
UiFlow2 Code Block:

MicroPython Code Block:
def calendar_event_handler(event_struct): if event_struct.get_code() == lv.EVENT.VALUE_CHANGED: date = lv.calendar_date_t() if calendar_0.get_pressed_date(date) == lv.RESULT.OK: calendar_0.set_today_date(date.year, date.month, date.day) print("Clicked date: %02d.%02d.%02d" % (date.year, date.month, date.day)) calendar_0.add_event_cb(calendar_event_handler, lv.EVENT.ALL, None)
- set_calendar_style(style)
Set the style of the calendar header.
- Parameters:
style (str) – The style of the calendar header, can be “arrow”, “dropdown”, or None.
UiFlow2 Code Block:

MicroPython Code Block:
calendar_0.set_calendar_style("arrow") calendar_0.set_calendar_style("dropdown") calendar_0.set_calendar_style(None)

