Reputation: 13
I need the program to be opened by double clicking on the tray icon.
Like this:
def show(icon, item):
icon.stop()
root.after(0, root.deiconify())
icon = pystray.Icon("name", image, "Title", menu)#, doubleclick=show())
icon.run()
Upvotes: 1
Views: 1720
Reputation: 14708
Unfortunately according to its own docs, pystray
cannot listen for click or double-click events on the icon itself, presumably because there is no system-independent way to do it. This is also a limitation of the other system tray Python library, infi.systray
.
Your example is not runnable, so I expanded on it. This snippet can run, and uses the standard device-independent drop-down menu method to start your tkinter app:
import tkinter as tk
import pystray
from PIL import Image
APP_ICON_FILEPATH = "pan.ico"
root = tk.Tk()
root.title("Pan's Labyrinth")
def show_app(icon, item):
print("Stop the icon")
icon.stop()
print("Start the program")
root.after(0, root.mainloop())
menu_options = [pystray.MenuItem("show_app", show_app)]
with Image.open(APP_ICON_FILEPATH) as icon_image:
this_icon = pystray.Icon("name", icon_image, "Title", menu_options)
this_icon.run()
Upvotes: 0