1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/examples/widgets/dropdown/lv_example_dropdown_3.py

47 lines
1.3 KiB
Python

# Create an image from the png file
try:
with open('../../assets/img_caret_down.png','rb') as f:
png_data = f.read()
except:
print("Could not find image_caret_down.png")
sys.exit()
image_caret_down_argb = lv.image_dsc_t({
'data_size': len(png_data),
'data': png_data
})
def event_cb(e):
dropdown = e.get_target_obj()
option = " "*64 # should be large enough to store the option
dropdown.get_selected_str(option, len(option))
print(option.strip() +" is selected")
#
# Create a menu from a drop-down list and show some drop-down list features and styling
#
# Create a drop down list
dropdown = lv.dropdown(lv.screen_active())
dropdown.align(lv.ALIGN.TOP_LEFT, 10, 10)
dropdown.set_options("\n".join([
"New project",
"New file",
"Open project",
"Recent projects",
"Preferences",
"Exit"]))
# Set a fixed text to display on the button of the drop-down list
dropdown.set_text("Menu")
# Use a custom image as down icon and flip it when the list is opened
# LV_IMAGE_DECLARE(image_caret_down)
dropdown.set_symbol(image_caret_down_argb)
dropdown.set_style_transform_rotation(1800, lv.PART.INDICATOR | lv.STATE.CHECKED)
# In a menu we don't need to show the last clicked item
dropdown.set_selected_highlight(False)
dropdown.add_event(event_cb, lv.EVENT.VALUE_CHANGED, None)