How to use screen load events to have objects initially hidden


I am using Gui Guider 1.4.1-GA with LVGL 8.2 (and Micropython). I am not using any hardware yet, just trying out the widgets and trying to understand the event model.

I have two images and I want them both hidden initially, on a button press a calculation is performed and depending on the result one of the two images is shown. Then there is a Clear button and they can both be hidden again.

I have the buttons working as I want, the only thing I can’t figure out is how to make them initially hidden. My guess is I would want to use either LV_EVENT_SCREEN_LOAD_START or LV_EVENT_SCREEN_LOADED. I don’t quite know what these events should be attached to, the images I want to hide or some screen object?

I’ve tried adding this to my, based on copying code that is generated in, but it is not quite right. Gui Guider doesn’t give much in the way of output when the Micropython fails to run, so I don’t have any debug output.

def hide_cb(e, img_to_hide):
    src = e.get_target()
    code = e.get_code()

screen_img_happy.add_event_cb(lambda e: hide_cb(e, screen_img_happy), lv.event.SCREEN_LOADED, None)
screen_img_angry.add_event_cb(lambda e: hide_cb(e, screen_img_angry), lv.event.SCREEN_LOADED, None)

Why not add the HIDDEN flag right after creating the objects?

Why indeed. I had tried that first and it didn’t work. I now realise it was because I was trying to write set_flag rather than add_flag. Good, another easy fix :slight_smile: thank you.