Infinidat / infi.systray

Windows system tray icon
BSD 3-Clause "New" or "Revised" License
215 stars 40 forks source link

how to pass parameter to menu option's function/command ? #25

Closed yctest9296 closed 4 years ago

yctest9296 commented 4 years ago

it is a quick question: how to pass parameter to menu option's function/command ? Thanks. like below:

def hello(sysTrayIcon, name):
    print "Hello "+name

menu_options = (('Say Hello', "hello.ico", hello('peter')), 
    ('Say Hello', "hello.ico", hello('jim')), ...
)
wiggin15 commented 4 years ago

Hi. This isn't supported directly, but can be easily worked around using lambda functions, like so:

def hello(sysTrayIcon, name):
    print "Hello "+name

menu_options = (('Say Hello', "hello.ico", lambda sysTrayIcon: hello(sysTrayIcon, 'peter')), 
    ('Say Hello', "hello.ico", lambda sysTrayIcon: hello(sysTrayIcon, 'jim')), ...
)