Scrolling in page by cycling through buttons using physical keys

Hi guys!
I am trying to create a custom list, for that I used a page and then created buttons with custom labels.
How can I make it scroll down (choose a button outside screen) just by pressing key up or down?
I can scroll through a list. But I am not being able to replicate the same behavior using a page and buttons.

Currently I am doing this:

prev_screen = lv.scr_act()
screen = lv.obj()

screen = header(screen)

page =
page.set_size(300, 144)
page.align(None, lv.ALIGN.CENTER, 0, -5)


for scheduledTask in lastUpdate['tasks']:
    btnUpdate = lv.btn(page)

    btnUpdateLabel = lv.label(btnUpdate)
    btnUpdateLabel.set_text("Date: "+scheduledTask['date']+"\n"+"Task: "+scheduledTask['name'])
    btnUpdate.set_event_cb(lambda obj, event, scheduledTask = scheduledTask: scheduled_task(None, scheduledTask) if event == lv.EVENT.CLICKED else None )
    lv.group_add_obj(group, btnUpdate)

And my add_group function is the following:

def add_group(group_type_list, list_obj = None):
    if group_type_list == True:
        group = lv.group_create() # Create a group
        lv.group_add_obj(group, list_obj) = group
        lv.group_set_style_mod_cb(group, None)
        lv.group_set_editing(group, True)
        tA._key = lv.KEY.LEFT
        tC._key = lv.KEY.RIGHT
        group = lv.group_create() = group
        #lv.group_set_style_mod_cb(group, None)
        tA._key = lv.KEY.PREV
        tC._key = lv.KEY.NEXT
    return group

Thank you for the help!

I don’t think this is Micropython specific question.
Same question would apply to C code, right?

Perhaps @embeddedt / @kisvegabor could comment.

1 Like

Ah yes indeed! It was the habit sorry! Moved to How-to

Take a look at the list implementation:

Essentially, you’d want to keep track of the currently focused button, find the next/previous button when a key is pressed, and call lv_page_focus on that.

1 Like

Hi @embeddedt thank you for your suggestion, taking it in consideration as well after reading I ended up solving it by simply adding:

lv.group_set_focus_cb(group, lambda x: page.focus(lv.group_get_focused(group),lv.ANIM.OFF))

Hope this helps someone in the future!

1 Like