You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am dynamically creating a menu including one submenu, both with a couple of items.
The submenu as well as the menu are created the same way as a list object and then being instanced as a pystray.Menu object.
The submenu
menu_intervals = []
for intervals_data in intervals:
menu_items_checked_state[intervals.get(intervals_data)] = not MenuItem.checked
menu_intervals.append(MenuItem(intervals.get(intervals_data), on_click_interval(Icon, intervals.get(intervals_data),
int(intervals_data)), default=False, checked=lambda MenuItem: menu_items_checked_state[MenuItem.text]))
interval_menu_counter += 1
menuItems.append(MenuItem("Auto Position Change", Menu(menu_intervals)))
systray_icon = Icon("Application", image_default, menu=menuItems)
From the documentation:
submenu
The submenu, if any, that is attached to this menu item. Either a submenu or an action can be passed as the second argument to the constructor.
The submenu must be an instance of Menu.
While creating and adding a Menu to Icon is working this way, it's running into a runtime error doing the same for Menu used as a submenu.
The text was updated successfully, but these errors were encountered:
Instead of menuItems.append(MenuItem("Auto Position Change", Menu(menu_intervals)))
it needs to be menuItems.append(MenuItem("Auto Position Change", Menu(lambda: menu_intervals)))
To highlight the difference: Menu(lambda: menu_intervals)
@moses-palmer This is quite hard to understand from the docs. I'd like to suggest to add a related example.
I am dynamically creating a menu including one submenu, both with a couple of items.
The submenu as well as the menu are created the same way as a list object and then being instanced as a pystray.Menu object.
The submenu
The Menu
And then adding it all together:
From the documentation:
While creating and adding a Menu to Icon is working this way, it's running into a runtime error doing the same for Menu used as a submenu.
The text was updated successfully, but these errors were encountered: