当前位置:首页 > 项目 > Wpython > 正文内容

LVGL_micropython 模拟器

Watrt2年前 (2022-12-07)Wpython11780

在使用micropython编写lvgl界面时有时间非常的麻烦。要在设备上才看得到效果。比较麻烦。npx的GUI-Guider软件中的模拟器给抠出来了单独使用,非常不错。

image.png

下面是运行实例:

import SDL
import utime as time
import usys as sys
import lvgl as lv
import lodepng as png
import ustruct

lv.init()
SDL.init(w=240,h=320)

# Register SDL display driver.
disp_buf1 = lv.disp_draw_buf_t()
buf1_1 = bytearray(240*10)
disp_buf1.init(buf1_1, None, len(buf1_1)//4)
disp_drv = lv.disp_drv_t()
disp_drv.init()
disp_drv.draw_buf = disp_buf1
disp_drv.flush_cb = SDL.monitor_flush
disp_drv.hor_res = 240
disp_drv.ver_res = 320
disp_drv.register()

# Regsiter SDL mouse driver
indev_drv = lv.indev_drv_t()
indev_drv.init() 
indev_drv.type = lv.INDEV_TYPE.POINTER
indev_drv.read_cb = SDL.mouse_read
indev_drv.register()
#==========================上面为调用SDL接口代码一般不用修改===========================


class CounterBtn():
    def __init__(self):
        self.cnt = 0
        #
        # Create a button with a label and react on click event.
        #

        btn = lv.btn(lv.scr_act())                               # Add a button the current screen
        btn.set_pos(10, 10)                                      # Set its position
        btn.set_size(120, 50)                                    # Set its size
        btn.align(lv.ALIGN.CENTER,0,0)
        btn.add_event_cb(self.btn_event_cb, lv.EVENT.ALL, None)  # Assign a callback to the button
        

        title = lv.label(lv.scr_act())                                    # Add a label to the button
        title.set_pos(5,5)
        title.set_text("http://www.xb6.cn")                                 # Set the labels text

        label = lv.label(btn)                                    # Add a label to the button
        label.set_text("Button")                                 # Set the labels text
        label.center()

    def btn_event_cb(self,evt):
        code = evt.get_code()
        btn = evt.get_target()
        if code == lv.EVENT.CLICKED:
            self.cnt += 1

        # Get the first child of the button which is the label and change its text
        label = btn.get_child(0)
        label.set_text("Button: " + str(self.cnt))


counterBtn = CounterBtn()



# ==============================调用刷新接口不能删除====================================
while SDL.check():
    time.sleep_ms(5)

lvgl_micropython.zip


分享给朋友:

相关文章

micrpython编译javascript版

micrpython编译javascript版

1、首先安装emsdkgit clone https://github.com/emscripten-core/emsdk.git cd <path-to-emsdk> git pull ./emsdk install latest ./emsdk activate latest source ./emsdk_env.sh2、获取micropython源码git clone&...

micropython 实现tar 文件解包

micropython 实现tar 文件解包

import upip_utarfile as tar import os def run(src,dest_dir):   t = tar.TarFile(src)   if not dest_dir in os.listdir():     os.mkdir(dest_dir)  ...

micropython 实现文件下载保存到本地

micropython 实现文件下载保存到本地

import sys import gc import ussl import usocket gc.collect() debug = False index_urls = ["https://micropython.org/pi", "https://pypi.org/pypi"] install_path = None c...

micropython 连接到mqtt

micropython 连接到mqtt

from umqtt.simple import MQTTClient from machine import Pin import ujson import urequests import network import time SERVER = "www.028sd.net" CLIENT_ID = "e...

micropython文本编辑器 界面

micropython文本编辑器 界面

##### startup script ##### #!/opt/bin/lv_micropython -i import lvgl as lv import display_driver ##### main script ##### import fs_driver fs_drv = lv.fs_drv_t() f...

micropython 日历页

micropython 日历页

# Initialize  import display_driver import lvgl as lv # Create a button with a label  # Copyright 2022 NXP # SPDX-License-Identifier: MIT # The ...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。