-
Notifications
You must be signed in to change notification settings - Fork 21
/
LamdaTrick.py
executable file
·44 lines (30 loc) · 989 Bytes
/
LamdaTrick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
'''
"lambda trick" test
A demo of a way to pass extra args in to callback
good for generating multiple gui items o code.
Use the menu to test it out!
'''
import wx
class TestFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
MenuBar = wx.MenuBar()
TestMenu = wx.Menu()
# build menu from data:
menu_names = ['item 1', 'item 2', 'item 3']
for name in menu_names:
item = TestMenu.Append(wx.ID_ANY, text=name)
self.Bind(wx.EVT_MENU,
(lambda evt, name = name:
self.onMenuSelect(evt, name)),
item)
MenuBar.Append(TestMenu , "&Test")
self.SetMenuBar(MenuBar)
def onMenuSelect(self, evt, menu_name):
print("Menu: %s was selected" %menu_name)
if __name__ == "__main__":
A = wx.App(False)
F = TestFrame(None)
F.Show()
A.MainLoop()