How to add a MenuItem to a ButtonMenu via code?

I want to add a MenuItem of the new m3 theme to a ButtonMenu via code:

from m3._Components.MenuItem import MenuItem
MenuItem(text="My Menu Item")
self.my_button_menu ...   # what do I need here?

I tried to use add_component()" method of the button menu object, or set the menu_items, but this seems to be always None`. What is the correct way to dynamically add menu items, and in which functions is this possible?

What you need to do is just set the menu_items prop to a list that contains your components:

self.test_item = MenuItem(text="My Menu Item")
self.my_button_menu.menu_items = [self.test_item]
1 Like

That’s it, thank you very much!

1 Like