0

Following this post, I've implemented to minimize the window of a app to system tray.

However, i don't figured out how to restore the window by clicking in the system's tray icon. Only opening the menu and choosing 'show' optin this is possible. Clicking at the icon, a TypeError raises:

File "C:\<path>\pystray\_base.py", line 106, in __call__
self._menu(self)
TypeError: 'tuple' object is not callable

Any hint for me? Thanks

  • it is telling you that `self._menu` is a tuple and you can't obviously call a tuple, so for example `self._menu = (1, 2, 3)` and you attempt to do `(1, 2, 3)()` – Matiiss Nov 16 '21 at 14:21
  • I see. However the right-click over the icon works for show the menu, but the left-click doesn't. In the code, the 'menu' variable is defined as a tuple with the options of the menu. – Andre Lucato Nov 16 '21 at 18:19

1 Answers1

1

You need to assign the menu option an instance of pystray.Menu instead of passing a tuple:

...
from pystray import Menu, MenuItem, Icon
...
def withdraw_window():  
    window.withdraw()
    image = Image.open("icon.png")
    # create instance of pystray.Menu instead of a tuple
    menu = Menu(
        MenuItem('Quit', quit_window),
        MenuItem('Show', show_window, default=True) # set 'Show' as the default action
    )
    icon = Icon("name", icon=image, title="title", menu=menu)
    icon.run()
...
acw1668
  • 40,144
  • 5
  • 22
  • 34