- Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathCenterTest.py
More file actions
Latest commit
executable file
·47 lines (37 loc) · 1.37 KB
/
Copy pathCenterTest.py
File metadata and controls
executable file
·47 lines (37 loc) · 1.37 KB
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
#!/usr/bin/env python
importwx
classMyPanel(wx.Panel):
def__init__(self, parent):
wx.Panel.__init__(self, parent, -1)
b=wx.Button(self, -1, "Hello")
b.Bind(wx.EVT_BUTTON, self.OnClick)
# the Bind() method removes the need to keep track of IDs
Sizer=wx.BoxSizer(wx.VERTICAL)
## by adding a stretchable spacer above and below, you get the
## button centered.
Sizer.Add((1,1), 1) ## this adds a 1X1 pixel spacer
## but the "1" means that it has a stretch factor of 1
Sizer.Add(b, 0, wx.ALIGN_CENTER) # the "0" means it won't stretch
Sizer.Add((1,1), 2) # same as above
# try changing the stretch factors, and see what you get.
self.SetSizer(Sizer)
defOnClick(self, event):
msgdialog=wx.MessageDialog(self,"HELLO WHIRLED",style=wx.OK)
msgdialog.ShowModal()
classMyFrame(wx.Frame):
def__init__(self, parent=None, id=-1, title='Wombat',
pos=wx.DefaultPosition, size=(200, 200)):
wx.Frame.__init__(self, parent, id, title, pos, size)
panel=MyPanel(self)
classApp(wx.App):
defOnInit(self):
frame=MyFrame()
frame.Center()
frame.Show()
self.SetTopWindow(frame)
returnTrue
defmain():
app=App()
app.MainLoop()
if__name__=='__main__':
main()