ok here the way i must do to aligne.
Since the alignment seem to work with the forme but on the center of the form i must size the forme and then offset the alignment with this offset.
but only for the bottom and the right of the screen.
This way the aligne work.
import machine
import esp32
import time
import sdcard
import os
import lvgl as lv
led = machine.Pin(5, machine.Pin.OUT)
led.off()
print(“Pin ready”)
Import ILI9341 driver and initialized it
import ili9XXX
disp = ili9XXX.ili9341(miso=19, mosi=23, clk=18, dc=27, cs=14, rst=33,
power=-1, backlight=-1, mhz=20,
width=320, height=240, rot=ili9XXX.REVERSE_LANDSCAPE)
Import XPT2046 driver and initalize it
from xpt2046 import xpt2046
touch = xpt2046(cs=12,mhz=5)
main script
def event_handler(evt):
code = evt.get_code()
if code == lv.EVENT.CLICKED:
print("Clicked event seen")
elif code == lv.EVENT.VALUE_CHANGED:
print("Value changed seen")
create a simple button
btn1 = lv.btn(lv.scr_act())
attach the callback
btn1.add_event_cb(event_handler,lv.EVENT.ALL, None)
btn1.align(lv.ALIGN.CENTER,0,-40)
label=lv.label(btn1)
label.set_text(“Button”)
create a toggle button
btn2 = lv.btn(lv.scr_act())
attach the callback
#btn2.add_event_cb(event_handler,lv.EVENT.VALUE_CHANGED,None)
btn2.add_event_cb(event_handler,lv.EVENT.ALL, None)
btn2.align(lv.ALIGN.CENTER,0,40)
btn2.add_flag(lv.obj.FLAG.CHECKABLE)
label=lv.label(btn2)
label.set_text(“Toggle”)
label.center()
led.on()
time.sleep(1)
led.off()
time.sleep(.5)