Replies: 1 comment 1 reply
-
|
The only place I see you centering a label is outside of the thread loop. Which is fine but as a suggestion try using the give this a go and se what happens.. from micropython import const
import lvgl as lv
import time
# you don' t need this imported.
# import task_handler
# from machine import Timer
# make sure you are not running task_handler
# at all in your display setup code.
import lv_config # display setup
import _thread
import sys
import random
import gc
# ========== Start UI ========== #
# this is a better thing to do because there is already a
# screen that exists
scrn = lv.screen_active()
# scrn = lv.obj()
bar1 = lv.bar(scrn)
bar1.set_pos(20, 20)
bar2 = lv.bar(scrn)
bar2.set_pos(20, 80)
btn = lv.button(scrn)
# btn.set_size(100, 50)
# btn.align(lv.ALIGN.CENTER, 0, 50)
# ========== Look here ========== #
# ========== Here is the problem ========== #
# btn_label = lv.label(scrn) # works
btn_label = lv.label(btn)
btn_label.set_text("Click")
btn_label..center()
btn.align(lv.ALIGN.CENTER, 0, 50)
# don't need this anymore
# lv.screen_load(scrn)
lv.tick_inc(1)
lv.refr_now(scrn.get_display())
def do():
# you don't want to set this any larger than 33 milliseconds
# otherwise it will make the input really sluggish.
sleep_delay = 33
start_time = time.ticks_ms()
while True:
s1_value = int(random.random() * 100.0)
s2_value = int(random.random() * 100.0)
bar1.set_value(s1_value, lv.ANIM.ON)
bar2.set_value(s2_value, lv.ANIM.ON)
end_time = time.ticks_ms()
diff = time.ticks_diff(end_time, start_time)
start_time = end_time
lv.tick_inc(diff)
lv.task_handler()
gc.collect()
if diff < sleep_delay:
time.sleep_ms(sleep_delay - diff if diff < sleep_delay else 0)
_thread.start_new_thread(do, ()) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The code shown is working when all widgets are placed directly on the screen. Even the bars get updated with random values.
However, as soon as I try to center the label on the button (as a child) it results in a crash without further error information.
Is there any obvious mistake in this code?
Im running LVGL 9.3 / MPY 1.25.0 on the CYD.
Beta Was this translation helpful? Give feedback.
All reactions