]>
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 | import wx # This module uses the new wx namespace | |
9 | print "wx.VERSION_STRING = ", wx.VERSION_STRING | |
10 | ||
11 | ||
12 | #import os; print os.getpid(); raw_input("press a key...") | |
13 | ||
14 | class MyFrame(wx.Frame): | |
15 | """ | |
16 | This is MyFrame. It just shows a few controls on a wxPanel, | |
17 | and has a simple menu. | |
18 | """ | |
19 | def __init__(self, parent, title): | |
20 | wx.Frame.__init__(self, parent, -1, title, size=(350, 200)) | |
21 | ||
22 | menuBar = wx.MenuBar() | |
23 | menu = wx.Menu() | |
24 | menu.Append(101, "E&xit\tAlt-X", "Exit demo") | |
25 | wx.EVT_MENU(self, 101, self.OnButton) | |
26 | menuBar.Append(menu, "&File") | |
27 | self.SetMenuBar(menuBar) | |
28 | ||
29 | panel = wx.Panel(self, -1) | |
30 | text = wx.StaticText(panel, -1, "Hello World!") | |
31 | text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) | |
32 | text.SetSize(text.GetBestSize()) | |
33 | btn = wx.Button(panel, -1, "Close") | |
34 | btn.SetDefault() | |
35 | ||
36 | btn2 = wx.Button(panel, -1, "Just for fun...") | |
37 | ||
38 | sizer = wx.BoxSizer(wx.VERTICAL) | |
39 | sizer.Add(text, 0, wx.ALL, 10) | |
40 | sizer.Add(btn, 0, wx.ALL, 10) | |
41 | sizer.Add(btn2, 0, wx.ALL, 10) | |
42 | panel.SetSizer(sizer) | |
43 | panel.SetAutoLayout(True) | |
44 | panel.Layout() | |
45 | ||
46 | wx.EVT_BUTTON(self, btn.GetId(), self.OnButton) | |
47 | wx.EVT_BUTTON(self, btn2.GetId(), self.OnFunButton) | |
48 | ||
49 | def OnButton(self, evt): | |
50 | """Event handler for the button click.""" | |
51 | print "OnButton" | |
52 | self.Close() | |
53 | ||
54 | def OnFunButton(self, evt): | |
55 | """Event handler for the button click.""" | |
56 | print "Having fun yet?" | |
57 | ||
58 | ||
59 | app = wx.PySimpleApp() | |
60 | frame = MyFrame(None, "Simple wxPython App") | |
61 | frame.Show(True) | |
62 | app.MainLoop() | |
63 |