python - 使用 Python/pystray,如何通过单击从系统托盘图标最大化窗口?
问题描述
在这篇文章之后,我实现了将应用程序的窗口最小化到系统托盘。
但是,我不知道如何通过单击系统的托盘图标来恢复窗口。只能打开菜单并选择“显示”选项。单击该图标,会引发 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()
...
推荐阅读
- python-3.x - 如何在强制 Lambda 函数运行两次的 AWS Lambda 中强制打印异常和错误?
- r - 在函数调用内部构造的 glms 上的 step/stepAIC
- android - 谷歌移动视觉 api - 将面部裁剪为来自相机的位图
- python - MacOS Big Sur - Python ctypes find_library 找不到库(ssl、CoreFoundation 等
- java - 继承私有值时如何创建复制构造函数?
- javascript - 如何通过按一下按钮将 HTML 范围滑块重置为默认位置和默认播放速率值
- regex - 如何排除特定句子而不是包含特定单词的整行 Notepad++ 或任何可以做到这一点的程序
- typescript - Typescript 3.0 项目参考的 Jest 编译问题
- asp.net - 在 asp.net 中集成 mailchimp api
- javascript - 在悬停时一一选择css中的所有孩子