在这篇文章之后,我实现了将应用程序的窗口最小化到系统托盘。
但是,我不知道如何通过单击系统的托盘图标来恢复窗口。只能打开菜单并选择“显示”选项。单击该图标,会引发 TypeError:
File "C:\<path>\pystray\_base.py", line 106, in __call__
self._menu(self)
TypeError: 'tuple' object is not callable
对我有什么提示吗?谢谢
您需要为menu
选项分配一个实例pystray.Menu
而不是传递一个元组:
...
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()
...