]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/simple/simple.py
fixed some docstrings
[wxWidgets.git] / wxPython / samples / simple / simple.py
1 #----------------------------------------------------------------------
2 # A very simple wxPython example. Just a wxFrame, wxPanel,
3 # wxStaticText, wxButton, and a wxBoxSizer, but it shows the basic
4 # structure of any wxPython application.
5 #----------------------------------------------------------------------
6
7 import wx
8
9
10 class MyFrame(wx.Frame):
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 wx.Frame.__init__(self, parent, -1, title, size=(350, 200))
17
18 # Create the menubar
19 menuBar = wx.MenuBar()
20
21 # and a menu
22 menu = wx.Menu()
23
24 # add an item to the menu, using \tKeyName automatically
25 # creates an accelerator, the third param is some help text
26 # that will show up in the statusbar
27 menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")
28
29 # bind the menu event to an event handler
30 self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)
31
32 # and put the menu on the menubar
33 menuBar.Append(menu, "&File")
34 self.SetMenuBar(menuBar)
35
36 self.CreateStatusBar()
37
38
39 # Now create the Panel to put the other controls on.
40 panel = wx.Panel(self)
41
42 # and a few controls
43 text = wx.StaticText(panel, -1, "Hello World!")
44 text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
45 text.SetSize(text.GetBestSize())
46 btn = wx.Button(panel, -1, "Close")
47 funbtn = wx.Button(panel, -1, "Just for fun...")
48
49 # bind the button events to handlers
50 self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)
51 self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)
52
53 # Use a sizer to layout the controls, stacked vertically and with
54 # a 10 pixel border around each
55 sizer = wx.BoxSizer(wx.VERTICAL)
56 sizer.Add(text, 0, wx.ALL, 10)
57 sizer.Add(btn, 0, wx.ALL, 10)
58 sizer.Add(funbtn, 0, wx.ALL, 10)
59 panel.SetSizer(sizer)
60 panel.Layout()
61
62
63 def OnTimeToClose(self, evt):
64 """Event handler for the button click."""
65 print "See ya later!"
66 self.Close()
67
68 def OnFunButton(self, evt):
69 """Event handler for the button click."""
70 print "Having fun yet?"
71
72
73 app = wx.PySimpleApp()
74 frame = MyFrame(None, "Simple wxPython App")
75 frame.Show(True)
76 app.MainLoop()
77