简体   繁体   中英

With Python/pystray, how to maximize a window from the system tray icon by clicking it?

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

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()
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM