]>
Commit | Line | Data |
---|---|---|
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 | ||
8 | from wxPython.wx import * | |
9 | ||
10 | class MyFrame(wxFrame): | |
11 | """ | |
12 | This is MyFrame. It just shows a few controls on a wxPanel, | |
13 | and has a simple menu. | |
14 | """ | |
15 | def __init__(self, parent, title): | |
16 | wxFrame.__init__(self, parent, -1, title, size=(350, 200)) | |
17 | ||
18 | menuBar = wxMenuBar() | |
19 | menu = wxMenu() | |
20 | menu.Append(101, "E&xit\tAlt-X", "Exit demo") | |
21 | EVT_MENU(self, 101, self.OnButton) | |
22 | menuBar.Append(menu, "&File") | |
23 | self.SetMenuBar(menuBar) | |
24 | ||
25 | panel = wxPanel(self, -1) | |
26 | text = wxStaticText(panel, -1, "Hello World!") | |
27 | text.SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD)) | |
28 | text.SetSize(text.GetBestSize()) | |
29 | btn = wxButton(panel, -1, "Close") | |
30 | btn.SetDefault() | |
31 | ||
32 | sizer = wxBoxSizer(wxVERTICAL) | |
33 | sizer.Add(text, 0, wxALL, 10) | |
34 | sizer.Add(btn, 0, wxALL, 10) | |
35 | panel.SetSizer(sizer) | |
36 | panel.SetAutoLayout(true) | |
37 | panel.Layout() | |
38 | ||
39 | EVT_BUTTON(self, btn.GetId(), self.OnButton) | |
40 | ||
41 | ||
42 | def OnButton(self, evt): | |
43 | """Event handler for the button click.""" | |
44 | print "OnButton" | |
45 | self.Close() | |
46 | ||
47 | app = wxPySimpleApp() | |
48 | frame = MyFrame(None, "Simple wxPython App") | |
49 | frame.Show(true) | |
50 | app.MainLoop() | |
51 |