]>
Commit | Line | Data |
---|---|---|
b6e5c445 RD |
1 | |
2 | #---------------------------------------------------------------------- | |
3 | # A very simple wxPython example. Just a wxFrame, wxPanel, | |
4 | # wxStaticText, wxButton, and a wxBoxSizer, but it shows the basic | |
5 | # structure of any wxPython application. | |
6 | #---------------------------------------------------------------------- | |
7 | ||
1fded56b | 8 | import wx # This module uses the new wx namespace |
b6e5c445 | 9 | |
1fded56b | 10 | class MyFrame(wx.Frame): |
b5a5d647 | 11 | """ |
a541c325 | 12 | This is MyFrame. It just shows a few controls on a wxPanel, |
b5a5d647 RD |
13 | and has a simple menu. |
14 | """ | |
b6e5c445 | 15 | def __init__(self, parent, title): |
1fded56b | 16 | wx.Frame.__init__(self, parent, -1, title, size=(350, 200)) |
b6e5c445 | 17 | |
1fded56b RD |
18 | menuBar = wx.MenuBar() |
19 | menu = wx.Menu() | |
b6e5c445 | 20 | menu.Append(101, "E&xit\tAlt-X", "Exit demo") |
1fded56b | 21 | wx.EVT_MENU(self, 101, self.OnButton) |
b6e5c445 RD |
22 | menuBar.Append(menu, "&File") |
23 | self.SetMenuBar(menuBar) | |
24 | ||
1fded56b RD |
25 | panel = wx.Panel(self, -1) |
26 | text = wx.StaticText(panel, -1, "Hello World!") | |
2f0f3b0f | 27 | text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) |
b6e5c445 | 28 | text.SetSize(text.GetBestSize()) |
1fded56b | 29 | btn = wx.Button(panel, -1, "Close") |
b6e5c445 RD |
30 | btn.SetDefault() |
31 | ||
2f0f3b0f RD |
32 | btn2 = wx.Button(panel, -1, "Just for fun...") |
33 | ||
1fded56b RD |
34 | sizer = wx.BoxSizer(wx.VERTICAL) |
35 | sizer.Add(text, 0, wx.ALL, 10) | |
36 | sizer.Add(btn, 0, wx.ALL, 10) | |
2f0f3b0f | 37 | sizer.Add(btn2, 0, wx.ALL, 10) |
b6e5c445 | 38 | panel.SetSizer(sizer) |
1e4a197e | 39 | panel.SetAutoLayout(True) |
b6e5c445 RD |
40 | panel.Layout() |
41 | ||
1fded56b | 42 | wx.EVT_BUTTON(self, btn.GetId(), self.OnButton) |
2f0f3b0f | 43 | wx.EVT_BUTTON(self, btn2.GetId(), self.OnFunButton) |
b6e5c445 RD |
44 | |
45 | def OnButton(self, evt): | |
b5a5d647 | 46 | """Event handler for the button click.""" |
4268f798 | 47 | print "OnButton" |
b6e5c445 RD |
48 | self.Close() |
49 | ||
2f0f3b0f RD |
50 | def OnFunButton(self, evt): |
51 | """Event handler for the button click.""" | |
52 | print "Having fun yet?" | |
53 | ||
1fded56b RD |
54 | |
55 | app = wx.PySimpleApp() | |
b6e5c445 | 56 | frame = MyFrame(None, "Simple wxPython App") |
1e4a197e | 57 | frame.Show(True) |
b6e5c445 RD |
58 | app.MainLoop() |
59 |