如何使用 tkinter 保留系统托盘图标
我正在尝试为风扇控制器创建代码,并且我已经达到了在关闭时创建系统托盘图标的程度,但是当您单击该图标以显示应用程序并再次关闭时,系统托盘图标不再出现,有人可以帮助我吗?这是负责系统托盘图标的代码部分:
from pystray import MenuItem as item
import pystray
from PIL import Image, ImageTk
def quit_window(icon, item):
icon.stop()
root.destroy()
def show_window(icon, item):
icon.stop()
root.after(0,root.deiconify())
def hide_window():
root.withdraw()
image=Image.open("../Resources/icon.png")
menu=(item('Quit', quit_window), item('Show', show_window))
icon=pystray.Icon("name", image, "My System Tray Icon", menu)
icon.run()
root = tk.Tk()
img = tk.Image("photo", file='../Resources/icon.png')
root.protocol('WM_DELETE_WINDOW', hide_window)
I'm trying to create a code for a fan controller and I already got to the point of creating a system tray icon when closed, but when you click the icon to show the app and close again, the system tray icon no longer appears, can someone help me? Here's the part of the code responsible for the system tray icon:
from pystray import MenuItem as item
import pystray
from PIL import Image, ImageTk
def quit_window(icon, item):
icon.stop()
root.destroy()
def show_window(icon, item):
icon.stop()
root.after(0,root.deiconify())
def hide_window():
root.withdraw()
image=Image.open("../Resources/icon.png")
menu=(item('Quit', quit_window), item('Show', show_window))
icon=pystray.Icon("name", image, "My System Tray Icon", menu)
icon.run()
root = tk.Tk()
img = tk.Image("photo", file='../Resources/icon.png')
root.protocol('WM_DELETE_WINDOW', hide_window)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论