显示屏
LCD 屏幕显示库
StopWatch includes a built-in round AMOLED display accessed through
M5.Lcd / M5.Display after M5.begin().
Read Text Layout for measured
width, overflow and vertical bounds, and
Resource Files and Paths before
loading an image or font file.
M5 系列显示库说明
1. Display 底层绘图库(M5.Lcd)
底层图形库,提供屏幕绘制、文字、线条、颜色管理等基础功能。
可独立使用,适合只需要绘制图形或文字的场景。
调用方式:
M5.Lcd.fillRect()、M5.Lcd.drawRect()、M5.Lcd.drawString()等。
2. M5Widgets
基础控件库,提供标签、图片显示等 UI 控件。
底层依赖 M5GFX。
适合需要简单交互控件的界面。
调用方式:
M5.Widgets.Label()、M5.Widgets.Image()、M5.Widgets.Rectangle()等。注意:
M5.Widgets提供 UI 组件 类,不提供绘图方法。建议:新的交互界面项目优先使用 M5UI/LVGL;简单界面或现有项目中的组件可使用 M5.Widgets。
3. M5UI
高层 UI 框架,基于 LVGL 封装。
提供页面管理、多控件布局和统一事件处理。
建议:新的交互界面项目优先使用 M5UI/LVGL。
使用提示
⚠️ 不建议同时混用 M5GFX、M5Widgets、M5UI,可能导致渲染异常或事件冲突。
单独绘图 → 使用 M5GFX。
简单控件交互 → 使用 M5Widgets。
多页面界面 → 使用 M5UI/LVGL(新项目推荐)。
常见错误及正确用法
❌ WRONG:
M5.Lcd.fill_rect()/draw_string()/set_text_color()-M5.Lcdmethods are camelCase only; snake_case raises AttributeErrorℹ️ NOT the same rule:
m5uiLabel.set_text_color()andImage.draw_string()are real snake_case methods of those classes - check the object type, do not “fix” them by habit❌ 错误:
Widgets.fillRect()或Widgets.drawRect()——Widgets 模块中没有这些方法。✅ 正确:
M5.Lcd.fillRect()或M5.Lcd.drawRect()——通过 M5.Lcd 调用绘图方法。❌ 错误:
from M5 import Widgets; Widgets.fillRect(...)——Widgets 用于创建 UI 组件,不提供此绘图方法。✅ CORRECT:
import M5; M5.Lcd.fillRect(...)- M5.Lcd provides all drawing methods
主要区别:- M5.Lcd 提供绘图方法(fillRect、drawRect、drawCircle、drawString 等);- M5.Widgets 提供 UI 组件类(Label、Image、Rectangle、Circle 等)。
屏幕旋转方向
旋转值以主机的正常观看方向为基准。0、1、2、3 分别表示旋转 0°、90°、180°、270°,不能统一理解为竖屏或横屏;实际方向取决于主机型号和 M5GFX 版本。
正常显示方向
Core/Basic/Fire、Core2、CoreS3、StackChan:旋转值
0,逻辑尺寸320 × 240。Cardputer、Cardputer Adv、DinMeter、Station:旋转值
0,逻辑尺寸240 × 135。CoreP4X:旋转值
0,逻辑尺寸480 × 480。
以上取值对应本文档配套的固件,旧固件的方向映射可能不同。对于上述 320 × 240 主机,旋转值为 1 或 3 时,逻辑尺寸为 240 × 320;为 0 或 2 时,逻辑尺寸为 320 × 240。
对于 CoreP4X 这样的方形屏幕,四个旋转方向的宽高相同,需要通过文字朝向或四角标记确认显示方向。
旧示例迁移
Core/Basic/Fire、Core2、CoreS3 和 StackChan 的旧示例中,用于正常横屏的 Widgets.setRotation(1) 现在应改为 Widgets.setRotation(0);M5.Lcd.setRotation() 同理。
图形化工程需要同时更新 .m5f2 的屏幕旋转设置和工程内的旋转积木,并检查生成的 Python;保存后重新打开工程,确认设置仍然正确。
使用 M5UI/LVGL 时,应在调用 m5ui.init() 前设置旋转方向,使界面按预期的屏幕尺寸初始化。
其他主机以及有意旋转显示的布局,应按预期效果选择旋转值,不要将所有 1 一律替换为 0。
修改方向后,通过 M5.Lcd.width() 和 M5.Lcd.height() 检查逻辑宽高。坐标原点位于左上角,X 向右增大,Y 向下增大。带触摸屏的主机还应检查四角触点与显示位置是否一致。
import M5
from M5 import Widgets
M5.begin()
Widgets.setRotation(0)
width = M5.Lcd.width()
height = M5.Lcd.height()
UiFlow2 应用示例
基础绘图
在 UiFlow2 上打开 cores3_draw_test_example.m5f2 项目。
本示例演示了 M5.Lcd 的基本绘图功能,包括文字、图片、二维码以及各种图形。
UiFlow2 代码块:
示例输出:
无
画布绘图
在 UiFlow2 上打开 cores3_display_canvas_example.m5f2 项目。
本示例演示了如何创建和使用画布进行绘图。它创建一个 2 位颜色深度的画布,在上面绘制圆形,然后将画布推送到显示屏。
UiFlow2 代码块:
示例输出:
无
MicroPython 应用示例
基础绘图
本示例演示了 M5.Lcd 的基本绘图功能,包括文字、图片、二维码以及各种图形。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4import os, sys, io 5import M5 6from M5 import * 7 8 9def setup(): 10 M5.begin() 11 Widgets.setRotation(0) 12 Widgets.fillScreen(0x222222) 13 14 print((str("rotation: ") + str((M5.Display.getRotation())))) 15 print( 16 ( 17 str((str("w: ") + str((M5.Display.width())))) 18 + str((str("h:") + str((M5.Display.height())))) 19 ) 20 ) 21 M5.Display.setRotation(0) 22 M5.Display.clear(0x000000) 23 M5.Display.setTextColor(0x0000FF, 0x000000) 24 M5.Display.setCursor(200, 3) 25 M5.Display.printf("hello M5") 26 M5.Display.print("hello M5", 0x6600CC) 27 M5.Display.drawImage("/flash/res/img/default.png", 0, 0) 28 M5.Display.drawQR("Hello", 220, 40, 100, 1) 29 M5.Display.drawCircle(30, 80, 20, 0x3333FF) 30 M5.Display.fillCircle(80, 80, 20, 0x009900) 31 M5.Display.drawEllipse(60, 140, 50, 30, 0x00FF00) 32 M5.Display.fillEllipse(60, 140, 30, 20, 0xFFFF00) 33 M5.Display.drawLine(115, 10, 115, 60, 0xFF0000) 34 M5.Display.drawRect(125, 10, 40, 30, 0xFF0000) 35 M5.Display.fillRect(125, 50, 40, 30, 0x00FF00) 36 M5.Display.drawTriangle(135, 150, 110, 190, 160, 190, 0x00FF00) 37 M5.Display.fillTriangle(145, 150, 170, 190, 190, 150, 0x0000FF) 38 M5.Display.drawArc(10, 180, 40, 45, 0, 90, 0xFFFF00) 39 M5.Display.fillArc(20, 190, 40, 45, 0, 90, 0x00FFFF) 40 41 42def loop(): 43 M5.update() 44 45 46if __name__ == "__main__": 47 try: 48 setup() 49 while True: 50 loop() 51 except (Exception, KeyboardInterrupt) as e: 52 try: 53 from utility import print_error_msg 54 55 print_error_msg(e) 56 except ImportError: 57 print("please update to latest firmware")
示例输出:
无
画布绘图
本示例演示了如何创建和使用画布进行绘图。它创建一个 2 位颜色深度的画布,在上面绘制圆形,然后将画布推送到显示屏。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4import os, sys, io 5import M5 6from M5 import * 7 8 9title0 = None 10canvas_rmy = None 11 12 13def setup(): 14 global title0, canvas_rmy 15 16 M5.begin() 17 Widgets.setRotation(0) 18 Widgets.fillScreen(0x222222) 19 title0 = Widgets.Title( 20 "Display canvas example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.Montserrat18 21 ) 22 23 canvas_rmy = M5.Display.newCanvas(100, 100, 2, True) 24 canvas_rmy.drawCircle(30, 30, 20, 0xFFFFFF) 25 canvas_rmy.drawCircle(30, 50, 20, 0xFFFFFF) 26 canvas_rmy.drawCircle(50, 40, 20, 0xFFFFFF) 27 canvas_rmy.push(50, 30) 28 print((str("color depth: ") + str((canvas_rmy.getColorDepth())))) 29 30 31def loop(): 32 global title0, canvas_rmy 33 M5.update() 34 35 36if __name__ == "__main__": 37 try: 38 setup() 39 while True: 40 loop() 41 except (Exception, KeyboardInterrupt) as e: 42 try: 43 from utility import print_error_msg 44 45 print_error_msg(e) 46 except ImportError: 47 print("please update to latest firmware")
示例输出:
无
使用 Canvas 实现无闪烁动画
当一帧动画包含多次绘制操作时,不要直接在 M5.Lcd 上逐个擦除并重绘元素。屏幕可能显示刚被清空或只绘制了一部分的中间状态,从而产生闪烁。应预先创建一个离屏画布,在画布上绘制完整的一帧,准备好后再调用一次 push() 显示。
API 名称为 M5.Lcd,区分大小写。应在初始化时创建画布并重复使用;每帧都新建画布会浪费内存,还可能导致内存分配失败。
import time
import M5
from M5 import *
canvas = None
ball_x = 12
direction = 2
def setup():
global canvas
M5.begin()
# Only the animated region needs a canvas. PSRAM must be available when psram=True.
canvas = M5.Lcd.newCanvas(w=200, h=80, bpp=16, psram=True)
def loop():
global ball_x, direction
M5.update()
# Build the whole frame off-screen. Nothing below is visible yet.
canvas.fillRect(0, 0, 200, 80, 0x000000)
canvas.fillCircle(ball_x, 40, 12, 0x00FF00)
canvas.setTextColor(0xFFFFFF, 0x000000)
canvas.drawString("Canvas animation", 8, 8)
# Present the completed frame in one operation.
canvas.push(60, 80)
ball_x += direction
if ball_x <= 12 or ball_x >= 188:
direction = -direction
time.sleep_ms(16)
if __name__ == "__main__":
setup()
while True:
loop()
屏幕其余区域保持静止时,只需为变化区域创建相应大小的画布。内存不足时,可缩小画布或降低颜色深度;设备没有 PSRAM 时,应设置 psram=False。不涉及中间帧状态的单次小范围更新仍可直接绘制。对于多步图形绘制、精灵、仪表或动画帧,建议在画布上完成绘制后,调用一次 push() 显示。
API参考
The examples below use M5.Lcd, the built-in display object. Initialize it
before running an example:
import M5
M5.begin()
M5.Display is an alias for M5.Lcd. from M5 import * also exports
the same object as Display and Lcd. The off-screen canvas objects
in the Canvas examples are separate drawing targets.
- class M5.Display
必须提供标为必填的参数。方法签名中列出了可选参数的默认值。绘制图元和调用
fillScreen()时,省略color或传入-1会复用当前绘图颜色。clear()使用当前底色。- width()
获取显示屏水平分辨率。
- 返回宽度:
水平分辨率。
- 返回类型:
int
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.width()
- height()
获取显示屏垂直分辨率。
- 返回高度:
垂直分辨率。
- 返回类型:
int
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.height()
- getRotation()
获取显示屏旋转方向。
- 返回旋转方向:
旋转方向值
- 返回类型:
int
旋转值:
0:旋转 0°
1:旋转 90°
2:旋转 180°
3:旋转 270°
The value can also be 4~7 for M5GFX mirrored orientations; see
setRotation()below. Display dimensions alone do not identify whether an orientation is mirrored.UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.getRotation()
- getColorDepth()
获取显示屏颜色深度。
- 返回颜色深度:
以每像素位数表示的颜色深度。
- 返回类型:
int
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.getColorDepth()
- getCursor()
获取显示屏绘图光标位置。
- 返回位置:
tuple (x, y) 光标位置。
- 返回类型:
tuple
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.getCursor()
- setRotation(r)
设置显示屏旋转。
- 参数:
r (int) – 旋转值(0~3):- 0:旋转 0°。- 1:旋转 90°。- 2:旋转 180°。- 3:旋转 270°。
备注
The Python binding does not reject values outside 0~3. Current M5GFX LCD/framebuffer drivers use the low three bits: 4~7 select mirrored orientations, and other integers wrap to 0~7 (for example, 8 becomes 0). A value of 4 can be returned by
getRotation()while width and height match rotation 0. Use 0~3 for ordinary rotation and validate application input before calling this method.各主机的显示尺寸及旧示例迁移方法见 屏幕旋转方向。使用 M5UI/LVGL 时,应在初始化界面前设置旋转方向。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.setRotation(2)
- setColorDepth(bpp)
设置画布的颜色深度。
- 参数:
bpp (int) – 期望的颜色深度(以每像素位数表示)。
注意:此方法仅适用于画布对象,不适用于显示屏本身。对于 CoreS3 设备,显示屏颜色深度固定为 16 位。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.setColorDepth(16)
- setEpdMode(epd_mode)
设置显示屏的 EPD 模式。
- 参数:
epd_mode (int) – desired EPD mode - 1: M5.Lcd.EPDMode.EPD_QUALITY - 2: M5.Lcd.EPDMode.EPD_TEXT - 3: M5.Lcd.EPDMode.EPD_FAST - 4: M5.Lcd.EPDMode.EPD_FASTEST
注意:仅适用于具有 EPD 功能的设备。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.setEpdMode(M5.Lcd.EPDMode.EPD_FAST)
- getEpdMode()
Return the current EPD refresh mode as an integer.
- 返回:
0 for a non-EPD display, or the current EPD mode: 1 (EPD_QUALITY), 2 (EPD_TEXT), 3 (EPD_FAST), or 4 (EPD_FASTEST).
- 返回类型:
This is the refresh mode, not a Boolean flag. Use
isEPD()to check display capabilities andsetEpdMode()to select a mode on an EPD display.MicroPython 代码块:
print(M5.Lcd.getEpdMode())
- isEPD()
检查显示屏是否为电子墨水屏(EPD)。
- 返回是否为 EPD:
如果显示屏为 EPD,则返回 True,否则返回 False。
- 返回类型:
bool
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.isEPD()
- setFont(font)
置显示字体。
- 参数:
font –
支持内置字体和字体文件(例如 .bin(lvgl 二进制字体格式)或 .vlw(Processing 字体格式))。可用的内置字体如下:
字体名称
状态
替代字体
不支持的设备
M5.Lcd.FONTS.ASCII7
❌ 已废弃
M5.Lcd.FONTS.Montserrat12
M5.Lcd.FONTS.DejaVu9
❌ 已废弃
M5.Lcd.FONTS.Montserrat12
M5.Lcd.FONTS.DejaVu12
❌ 已废弃
M5.Lcd.FONTS.Montserrat14
M5.Lcd.FONTS.DejaVu18
❌ 已废弃
M5.Lcd.FONTS.Montserrat18
M5.Lcd.FONTS.DejaVu24
❌ 已废弃
M5.Lcd.FONTS.Montserrat24
M5.Lcd.FONTS.DejaVu40
❌ 已废弃
M5.Lcd.FONTS.Montserrat40
M5.Lcd.FONTS.DejaVu56
❌ 已废弃
M5.Lcd.FONTS.Montserrat44
M5.Lcd.FONTS.DejaVu72
❌ 已废弃
M5.Lcd.FONTS.Montserrat48
M5.Lcd.FONTS.EFontCN24
❌ 已废弃
M5.Lcd.FONTS.AlibabaPuHuiTiCN24
M5.Lcd.FONTS.EFontJA24
❌ 已废弃
M5.Lcd.FONTS.AlibabaSansJA24
M5.Lcd.FONTS.EFontKR24
❌ 已废弃
M5.Lcd.FONTS.AlibabaSansKR24
M5.Lcd.FONTS.Montserrat12
✅ 推荐
M5.Lcd.FONTS.Montserrat14
✅ 推荐
M5.Lcd.FONTS.Montserrat16
✅ 推荐
M5.Lcd.FONTS.Montserrat18
✅ 推荐
M5.Lcd.FONTS.Montserrat24
✅ 推荐
M5.Lcd.FONTS.Montserrat40
✅ 推荐
M5.Lcd.FONTS.Montserrat48
✅ 推荐
M5.Lcd.FONTS.AlibabaPuHuiTiCN24
✅ 推荐
M5STACK_StickC_PLUS, M5STACK_CoreInk, M5STACK_StickC,
M5STACK_Atom_Lite, M5STACK_Stamp_PICO, M5STACK_Atom_Matrix,
M5STACK_AtomU, M5STACK_Atom_Echo, M5STACK_NanoC6
M5.Lcd.FONTS.AlibabaSansJA24
✅ 推荐
M5.Lcd.FONTS.AlibabaSansKR24
✅ 推荐
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.setFont(M5.Lcd.FONTS.DejaVu18)
- drawString(text, x, y, font=None)
Draw a string at the specified pixel coordinates using the current text color, text size, and the current or supplied font.
- 参数:
- 返回:
None. The Python wrapper does not return the drawn width.
To use a font file, load it with
setFont()first and omit thefontargument. To measure a string, usetextWidth().MicroPython 代码块:
M5.Lcd.drawString("Hello", 10, 20) M5.Lcd.drawString("World", 10, 50, M5.Lcd.FONTS.Montserrat18)
- textWidth(text, font=None)
Return the width of a string in pixels at the current text size.
- 参数:
text (str) – text to measure (required).
font – optional built-in font object from
M5.Lcd.FONTS.Noneuses the current font. In the current Python wrapper, supplying this argument also changes the current drawing font.
- 返回:
string width in pixels.
- 返回类型:
To measure text with a font file, load it with
setFont()first and omit thefontargument.MicroPython 代码块:
width = M5.Lcd.textWidth("Hello") print(width)
- fontHeight(font=None)
Return the font height in pixels at the current text size.
- 参数:
font – optional built-in font object from
M5.Lcd.FONTS.Nonemeasures the current font. Supplying a font here does not change the current drawing font.- 返回:
font height in pixels.
- 返回类型:
To measure a font file, load it with
setFont()first and omit thefontargument.MicroPython 代码块:
height = M5.Lcd.fontHeight() print(height)
- setTextColor(fgcolor, bgcolor=0x000000)
设置文本颜色和背景颜色。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.setTextColor(0xFF0000, 0x000000)
- setTextScroll(scroll)
启用或禁用文本滚动。
- 参数:
scroll (bool) – 设置为 True 启用文本滚动,设置为 False 禁用文本滚动(必填)
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.setTextScroll(True)
- setTextSize(size)
设置文本的大小。
- 参数:
size (int) – 期望的文本大小。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.setTextSize(2)
- setCursor(x, y)
设置光标位置。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.setCursor(10, 20)
- clear(color=-1)
使用指定颜色清空显示屏
- 参数:
color (int) – 填充颜色,使用 RGB888 格式(可选,省略或设为 -1 时复用当前底色)
警告
避免在循环或事件处理函数中调用
clear(),它会重绘所有像素,造成明显闪烁。更新动态内容时,可用fillRect()仅擦除变化区域,再绘制新内容。UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.clear(0xFFFFFF)
- fillScreen(color=-1)
用指定颜色填充整个屏幕。
- 参数:
color (int) – 填充颜色,使用 RGB888 格式(可选,省略或设为 -1 时复用当前绘图颜色)
警告
避免在循环或事件处理函数中调用
fillScreen(),它会重绘所有像素,造成明显闪烁。静态背景应在初始化时绘制一次;更新动态内容时,可用fillRect()仅清除变化区域。UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.fillScreen(0xFF0000)
- drawPixel(x, y, color=-1)
在屏幕上绘制单个像素。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawPixel(50, 50, 0x00FF00)
- drawCircle(x, y, r, color=-1)
绘制一个圆。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawCircle(60, 60, 20, 0x0000FF)
- fillCircle(x, y, r, color=-1)
绘制一个实心圆。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.fillCircle(60, 60, 20, 0x00FFFF)
- drawEllipse(x, y, rx, ry, color=-1)
绘制一个椭圆。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawEllipse(80, 40, 30, 20, 0xFF00FF)
- fillEllipse(x, y, rx, ry, color=-1)
绘制一个实心椭圆。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.fillEllipse(80, 40, 30, 20, 0x00FF00)
- drawLine(x0, y0, x1, y1, color=-1)
绘制一条直线。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawLine(10, 10, 100, 100, 0xFF0000)
- drawRect(x, y, w, h, color=-1)
绘制一个矩形。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawRect(20, 20, 80, 50, 0x00FF00)
- fillRect(x, y, w, h, color=-1)
绘制一个填充矩形。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.fillRect(20, 20, 80, 50, 0x0000FF)
- drawRoundRect(x, y, w, h, r, color=-1)
绘制一个圆角矩形。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawRoundRect(30, 30, 60, 40, 10, 0xFF00FF)
- fillRoundRect(x, y, w, h, r, color=-1)
绘制一个填充圆角矩形。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.fillRoundRect(30, 30, 60, 40, 10, 0x00FFFF)
- drawTriangle(x0, y0, x1, y1, x2, y2, color=-1)
绘制一个三角形。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawTriangle(10, 10, 50, 80, 90, 10, 0xFF0000)
- fillTriangle(x0, y0, x1, y1, x2, y2, color=-1)
绘制一个填充三角形。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.fillTriangle(10, 10, 50, 80, 90, 10, 0x00FF00)
- drawArc(x, y, r0, r1, angle0, angle1, color=-1)
绘制一个弧线。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawArc(50, 50, 20, 30, 0, 180, 0xFF0000)
- fillArc(x, y, r0, r1, angle0, angle1, color=-1)
绘制一个填充弧线。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.fillArc(50, 50, 20, 30, 0, 180, 0x00FF00)
- drawEllipseArc(x, y, r0x, r1x, r0y, r1y, angle0, angle1, color=-1)
绘制一个椭圆弧线。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawEllipseArc(50, 50, 20, 40, 10, 30, 0, 180, 0xFF00FF)
- fillEllipseArc(x, y, r0x, r1x, r0y, r1y, angle0, angle1, color=-1)
绘制一个填充椭圆弧线。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.fillEllipseArc(50, 50, 20, 40, 10, 30, 0, 180, 0x00FFFF)
- drawQR(text, x, y, w, version=1)
绘制二维码。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawQR("Hello", 0, 0, 200)
- drawPng(img, x=0, y=0, maxW=0, maxH=0, offX=0, offY=0, scaleX=1.0, scaleY=0.0)
绘制 PNG 图片。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawPng("res/img/uiflow.png", 0, 0)
示例:
M5.Lcd.drawPng("res/img/uiflow.png", 0, 0) img = open("res/img/uiflow.png", "b") img.seek(0) M5.Lcd.drawPng(img.read(), 0, 100) img.close()
- drawJpg(img, x=0, y=0, maxW=0, maxH=0, offX=0, offY=0, scaleX=1.0, scaleY=0.0)
绘制 JPG 图片。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawJpg("res/img/uiflow.jpg", 0, 0)
示例:
M5.Lcd.drawJpg("res/img/uiflow.jpg", 0, 0) img = open("res/img/uiflow.jpg", "b") img.seek(0) M5.Lcd.drawJpg(img.read(), 0, 100) img.close()
- drawBmp(img, x=0, y=0, maxW=0, maxH=0, offX=0, offY=0, scaleX=1.0, scaleY=0.0)
绘制 BMP 图片。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawBmp("res/img/uiflow.bmp", 0, 0)
示例:
M5.Lcd.drawBmp("res/img/uiflow.bmp", 0, 0) img = open("res/img/uiflow.bmp", "b") img.seek(0) M5.Lcd.drawBmp(img.read(), 0, 100) img.close()
- drawImage(img, x=0, y=0, maxW=0, maxH=0, offX=0, offY=0, scaleX=1.0, scaleY=0.0)
绘制图片。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
img = open("res/img/uiflow.jpg", "b")
示例:
img = open("res/img/uiflow.jpg", "b") img.seek(0) M5.Lcd.drawImage(img.read(), 0, 0) img.close()
- drawRawBuf(buf, x, y, w, h, len, swap=False)
绘制缓冲区中的图片。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.drawRawBuf(raw_buf, 0, 0, 100, 100, len(raw_buf), swap=False)
示例:
width, height = 40, 30 green565 = 0x07E0 raw_buf = bytearray(width * height * 2) for i in range(width * height): raw_buf[2*i] = (green565 >> 8) & 0xFF raw_buf[2*i+1] = green565 & 0xFF M5.Lcd.drawRawBuf(raw_buf, 100, 100, width, height, len(raw_buf), swap=False)
- print(text, color=-1)
显示字符串(不支持格式化)。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.print("Hello World", color=0xFF0000)
- printf(text)
显示格式化字符串。
- 参数:
text (str) – 要显示的格式化字符串。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.printf("Value: %d" % 100)
- newCanvas(w, h, bpp=-1, psram=False)
创建一个离屏画布。先在画布上绘制完整的一帧,再调用一次
push(x, y)显示。应重复使用返回的画布对象,避免在主循环中反复创建。UiFlow2 代码块:

MicroPython 代码块:
w1 = M5.Lcd.newCanvas(w=100, h=100, bpp=16)
示例:
w1 = M5.Lcd.newCanvas(w=100, h=100, bpp=16) w1.drawImage("res/img/uiflow.jpg", 80, 0) w1.push(30, 0)
- startWrite()
开始向显示屏写入内容。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.startWrite()
示例:
M5.Lcd.startWrite() M5.Lcd.drawPixel(10, 10, 0xFF0000) M5.Lcd.endWrite()
- endWrite()
结束显示屏写入。
UiFlow2 代码块:

MicroPython 代码块:
M5.Lcd.endWrite()

