M5Image
M5Image is a widget that can be used to create image in the user interface.
UiFlow2 Example
show image
Open the cores3_show_image_example.m5f2 project in UiFlow2.
This example shows how to display an image on the screen.
UiFlow2 Code Block:
Example output:
None
MicroPython Example
show image
This example shows how to display an image on the screen.
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 13image0 = None 14image1 = None 15 16 17def setup(): 18 global page0, image0, image1 19 20 M5.begin() 21 Widgets.setRotation(1) 22 m5ui.init() 23 page0 = m5ui.M5Page(bg_c=0xFFFFFF) 24 image0 = m5ui.M5Image("/flash/res/img/uiflow.jpg", x=129, y=54, parent=page0) 25 image1 = m5ui.M5Image("/flash/res/img/uiflow.png", x=129, y=118, parent=page0) 26 27 page0.screen_load() 28 image0.set_image("/flash/res/img/uiflow.jpg") 29 image1.set_image("/flash/res/img/uiflow.png") 30 31 32def loop(): 33 global page0, image0, image1 34 M5.update() 35 36 37if __name__ == "__main__": 38 try: 39 setup() 40 while True: 41 loop() 42 except (Exception, KeyboardInterrupt) as e: 43 try: 44 m5ui.deinit() 45 from utility import print_error_msg 46 47 print_error_msg(e) 48 except ImportError: 49 print("please update to latest firmware")
Example output:
None
API
M5Image
- class m5ui.image.M5Image(*args, **kwargs)
Bases:
imageCreate a image object.
- Parameters:
MicroPython Code Block:
from m5ui import M5Image import lvgl as lv m5ui.init() image_0 = M5Image("/flash/res/img/defalut.jpg", x=10, y=10, parent=page0) image_1 = M5Image("/flash/res/img/uiflow.jpg", x=50, y=50, parent=page0)
- set_flag(flag, value)
Set a flag on the object. If
valueis True, the flag is added; if False, the flag is removed.- Parameters:
UiFlow2 Code Block:

MicroPython Code Block:
image_0.set_flag(lv.obj.FLAG.HIDDEN, True)
- set_pos(x, y)
Set the position of the image.
UiFlow2 Code Block:

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

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

MicroPython Code Block:
image_0.set_y(100)
- align_to(obj, align, x, y)
Align the image to another object.
- Parameters:
UiFlow2 Code Block:

MicroPython Code Block:
image_0.align_to(page_0, lv.ALIGN.CENTER, 0, 0)
- set_image(path)
Set the image to be displayed.
- Parameters:
path (str) – The path of the image file.
UiFlow2 Code Block:

MicroPython Code Block:
image_0.set_image("/flash/res/img/uiflow.jpg") image_1.set_image("/sd/uiflow.png")


