]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/simple.py
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 #----------------------------------------------------------------------
8 import wx
# This module uses the new wx namespace
9 print "wx.VERSION_STRING = ", wx
.VERSION_STRING
12 #import os; print os.getpid(); raw_input("press a key...")
14 class MyFrame(wx
.Frame
):
16 This is MyFrame. It just shows a few controls on a wxPanel,
17 and has a simple menu.
19 def __init__(self
, parent
, title
):
20 wx
.Frame
.__init
__(self
, parent
, -1, title
, size
=(350, 200))
22 menuBar
= wx
.MenuBar()
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
)
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")
36 btn2
= wx
.Button(panel
, -1, "Just for fun...")
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)
43 panel
.SetAutoLayout(True)
46 wx
.EVT_BUTTON(self
, btn
.GetId(), self
.OnButton
)
47 wx
.EVT_BUTTON(self
, btn2
.GetId(), self
.OnFunButton
)
49 def OnButton(self
, evt
):
50 """Event handler for the button click."""
54 def OnFunButton(self
, evt
):
55 """Event handler for the button click."""
56 print "Having fun yet?"
59 app
= wx
.PySimpleApp()
60 frame
= MyFrame(None, "Simple wxPython App")