MicroPython with LVGL

 官方博客:Micropython + LittlevGL | LVGL’s Blog

github:GitHub - lvgl/lv_micropython: Micropython bindings to LVGL for Embedded devices, Unix and JavaScript

官方在线模拟器:https://sim.lvgl.io/(需要电脑能访问外网才能使用)

电脑不能访问外网会出现以下错误:

1、在界面上创建一个按钮

Micropython代码:

# Initialize

import display_driver
import lvgl as lv

# Create a button with a label

scr = lv.obj()
btn = lv.button(scr)
btn.align(lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn)
label.set_text('Hello World!')
lv.screen_load(scr)

 运行效果:

2、添加点击事件响应

Micropython代码:

# Initialize

import display_driver
import lvgl as lv

# Create a button with a label

scr = lv.obj()
btn = lv.button(scr)
btn.align(lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn)
label.set_text('Button')

# define callback function
def btn_event_cb(e):
    code = e.get_code()
    if code == lv.EVENT.CLICKED:
        print("Button clicked!")

btn.add_event_cb(btn_event_cb, lv.EVENT.ALL, None)

lv.screen_load(scr)

 运行效果:

鼠标左键点击Button,控制台会打印"Button clicked!"

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-08 10:42:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-08 10:42:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-08 10:42:01       82 阅读
  4. Python语言-面向对象

    2024-04-08 10:42:01       91 阅读

热门阅读

  1. css 手写返回箭头

    2024-04-08 10:42:01       35 阅读
  2. 【告警监控】监控,巡检和拨测

    2024-04-08 10:42:01       36 阅读
  3. Unity LayoutRebuilder 强制UI重新布局

    2024-04-08 10:42:01       31 阅读
  4. wpf viewmodel和界面双向通知

    2024-04-08 10:42:01       27 阅读
  5. tx-lcn使用

    2024-04-08 10:42:01       31 阅读
  6. WPF —— FromTo/By动画

    2024-04-08 10:42:01       32 阅读
  7. C#WPF控件Menu详解

    2024-04-08 10:42:01       30 阅读
  8. Springboot启动过程

    2024-04-08 10:42:01       32 阅读
  9. Docker设置时区

    2024-04-08 10:42:01       39 阅读
  10. opencv x86(32位) windows下vs2019编译问题

    2024-04-08 10:42:01       30 阅读
  11. 数据结构 实验报告11

    2024-04-08 10:42:01       37 阅读