I'm trying to pass extra arguments to a function that is called by an item in pystray menu.
import pystray
from pystray import MenuItem as item
from PIL import Image, ImageTk
def show_window(icon):
icon.notify('Hello World!', 'Hi')
def quit_window(icon, message):
print(message)
icon.stop()
icon = 'icon.ico'
image=Image.open(icon)
menu=pystray.Menu(item('Show', show_window, default=True), item('Quit', quit_window(icon, "Test")))
icon=pystray.Icon("name", image, "My System Tray Icon", menu)
icon.run()
In this example I'm trying to pass the argument "message" calling the function "quit_window" when I press "Quit" in pystray menu. The problem here is by default the functions used in menu construction don't have arguments and internally refers to icon. When I use arguments the constructor don't pass the icon reference to call stop() and since I create pystray.Icon after pystray.Menu I don't know how to pass this info and make it work.