Button create stops code

Hello,

Trying to run code below and looks like code stopes just after run line btn = lv.btn(scr) and I don’t see any picture. What might be wrong? How to solve this problem?

import sys
import lvgl as lv
try: 
    lv.init()
    print("start")
    scr = lv.obj()
    print("1")
    btn = lv.btn(scr)
    print("2")
    btn.align(lv.scr_act(), lv.ALIGN.CENTER, 0, 0)
    label = lv.label(btn)
    label.set_text("Button")
    lv.scr_load(scr)
    print("end")
except:
    print("Unexpected error:", sys.exc_info()[0])
    raise

Output:

start
1

UPD

I have updated code with display driver as recommended:

import sys
import time
import lvgl as lv
lv.init()

import SDL
SDL.init()

try:
    print("start")

    disp_buf1 = lv.disp_buf_t()
    buf1_1 = bytearray(480*10)
    print("1")
    disp_buf1.init(buf1_1, None, len(buf1_1)//4)
    disp_drv = lv.disp_drv_t()
    disp_drv.init()
    disp_drv.buffer = disp_buf1
    disp_drv.flush_cb = SDL.monitor_flush

    disp_drv.hor_res = 480
    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();


    
    scr = lv.obj()
    print("1")
    btn = lv.btn(scr)
    print("2")
    btn.align(lv.scr_act(), lv.ALIGN.CENTER, 0, 0)
    label = lv.label(btn)
    label.set_text("Button")
    lv.scr_load(scr)
    time.sleep(5)
    print("end")
except:
    print("Unexpected error:", sys.exc_info()[0])
    raise

Now it works and window blinks for 5 seconds and then program terminates. I suppose I must create loop that do not allow program terminate. How it should look?

Please provide more background:
What platform and Micropython port are you running? On what hardware? Which display? How is the display connected?

I don’t see you initialized any display driver so don’t expect to see anything.

Thanks for pointing to display driver. I’m trying to run on Raspberry Pi by using SDL. Display is standard HDMI monitor. I have updated question body with code.

Now it works and window blinks for second and then program terminates. I suppose I must create loop that do not allow program terminate. How it should look?

Try running:

micropython -i <script_file>

That would open the REPL after running your script.