How to provide dropdown submenus inside one tray menu as below shown in image using pystray library in python?

857 Views Asked by At

Here is my sample code:

    image = Image.open("E:\\production\\Windows utility tool\\images\\icon.ico")
    menu = (item("Sign in", show_window), item("Change status", status_online), item("Change icon", change_icon), item("Open application", open_application), item("Quit", quit_window))
    icon = pystray.Icon("Notifer", image, "notifier_application", menu)
    icon.run()

See sample image

1

There are 1 best solutions below

1
On BEST ANSWER

This is how the menu should be for drop down submenus

menu = (
Item('mainitem1', callable),
Item('mainitem2', callable),
Item('mainitem3', Menu(Item('subitem1', callable),Item('subitem2', callable))),
Item('mainitem4', callable)
        )

Make sure to add from pystray import Menu, MenuItem as Item at the beginning of the code.

Hope I gave you a proper answer.