-
Notifications
You must be signed in to change notification settings - Fork 21
/
ButtonArray.py
executable file
·55 lines (31 loc) · 1.15 KB
/
ButtonArray.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
45
46
47
48
49
50
#!/usr/bin/env python
import wx
class ButtonArrayPanel(wx.Panel):
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
Sizer = wx.GridSizer(16, 2, 0, 0)
for i in range(32):
B = wx.Button(self, label = "button %i"%i)
B.Bind(wx.EVT_BUTTON,
lambda evt, but_num = i: self.OnButton(evt, but_num) )
Sizer.Add(B, 0, wx.GROW|wx.ALL, 4)
self.SetSizerAndFit(Sizer)
def OnButton(self, evt, but_num):
print "Button number: %i clicked"%but_num
class DemoFrame(wx.Frame):
def __init__(self, title = "Button Array Demo"):
wx.Frame.__init__(self, None , -1, title)
btn = wx.Button(self, label = "Quit")
btn.Bind(wx.EVT_BUTTON, self.OnQuit )
BP = ButtonArrayPanel(self)
Sizer = wx.BoxSizer(wx.VERTICAL)
Sizer.Add(btn, 1, wx.CENTER|wx.ALL, 6)
Sizer.Add(BP, 0, wx.CENTER|wx.ALL, 4)
self.SetSizerAndFit(Sizer)
self.Bind(wx.EVT_CLOSE, self.OnQuit)
def OnQuit(self,Event):
self.Destroy()
app = wx.App(False)
frame = DemoFrame()
frame.Show()
app.MainLoop()