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