pystray
pystray copied to clipboard
Icon visibility not updating
So I've been having a weird issue: I initilize the tray just fine and all the buttons work, but when I click show window the tray icon doesn't disappear. If I close the window again, none of the buttons work on the tray (but they are visible). I am integrating with tkinter using the following code:
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()
icon.run()
image=Image.open(resource_path("altserver.ico"))
menu=(item('Show', show_window), item('Quit', quit_window))
icon=pystray.Icon("name", image, "AltServer", menu)
root.protocol('WM_DELETE_WINDOW', hide_window)
root.mainloop()
I read #124, and tried the suggestion there to run the icon in a separate thread and manipulate the visibility instead:
def hide_window():
root.withdraw()
icon.visible = True
def startTray(icon):
print("Starting tray")
def quit_window(icon, item):
icon.stop()
root.destroy()
def show_window(icon, item):
icon.visible = False
root.after(0, root.deiconify())
def installAltStoreTray(icon, item):
show_window(icon, item)
installAltStore()
image=Image.open(resource_path("altserver.ico"))
menu=(item("Install AltStore", installAltStoreTray), item('Show', show_window), item('Quit', quit_window))
icon=pystray.Icon("name", image, "AltServer", menu)
threading.Thread(target=lambda:icon.run(startTray)).start()
And this has the exact same result (tray works the first time, doesn't disappear, no buttons work the second time) I am running Linux Mint 20.3 and python3.8.
I have exactly the same issue, but I use only .run() (no embedding into another framework).
I can also add, that in my installation the AppIndicator is used.
For the cause (and a fix) see #134.
@nab138, #134 has been merged. Did this solve your issue?