]>
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 | def __init__(self, parent, title): | |
12 | wxFrame.__init__(self, parent, -1, title, size=(350, 200)) | |
13 | ||
14 | menuBar = wxMenuBar() | |
15 | menu = wxMenu() | |
16 | menu.Append(101, "E&xit\tAlt-X", "Exit demo") | |
17 | EVT_MENU(self, 101, self.OnButton) | |
18 | menuBar.Append(menu, "&File") | |
19 | self.SetMenuBar(menuBar) | |
20 | ||
21 | panel = wxPanel(self, -1) | |
22 | if wxPlatform == "__WXMAC__": | |
23 | text = wxStaticText(panel, -1, "Hello World!\nWhere is my menu?") | |
24 | else: | |
25 | text = wxStaticText(panel, -1, "Hello World!") | |
26 | text.SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD)) | |
27 | text.SetSize(text.GetBestSize()) | |
28 | btn = wxButton(panel, -1, "Close") | |
29 | btn.SetDefault() | |
30 | ||
31 | sizer = wxBoxSizer(wxVERTICAL) | |
32 | sizer.Add(text, 0, wxALL, 10) | |
33 | sizer.Add(btn, 0, wxALL, 10) | |
34 | panel.SetSizer(sizer) | |
35 | panel.SetAutoLayout(true) | |
36 | panel.Layout() | |
37 | ||
38 | EVT_BUTTON(self, btn.GetId(), self.OnButton) | |
39 | ||
40 | ||
41 | def OnButton(self, evt): | |
42 | self.Close() | |
43 | ||
44 | app = wxPySimpleApp() | |
45 | frame = MyFrame(None, "Simple wxPython App") | |
46 | frame.Show(true) | |
47 | app.MainLoop() | |
48 |