]>
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
10 class MyFrame(wx
.Frame
):
12 This is MyFrame. It just shows a few controls on a wxPanel,
13 and has a simple menu.
15 def __init__(self
, parent
, title
):
16 wx
.Frame
.__init
__(self
, parent
, -1, title
, size
=(350, 200))
18 menuBar
= wx
.MenuBar()
20 menu
.Append(101, "E&xit\tAlt-X", "Exit demo")
21 wx
.EVT_MENU(self
, 101, self
.OnButton
)
22 menuBar
.Append(menu
, "&File")
23 self
.SetMenuBar(menuBar
)
25 panel
= wx
.Panel(self
, -1)
26 text
= wx
.StaticText(panel
, -1, "Hello World!")
27 text
.SetFont(wx
.Font(12, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
28 text
.SetSize(text
.GetBestSize())
29 btn
= wx
.Button(panel
, -1, "Close")
32 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
33 sizer
.Add(text
, 0, wx
.ALL
, 10)
34 sizer
.Add(btn
, 0, wx
.ALL
, 10)
36 panel
.SetAutoLayout(True)
39 wx
.EVT_BUTTON(self
, btn
.GetId(), self
.OnButton
)
42 def OnButton(self
, evt
):
43 """Event handler for the button click."""
48 app
= wx
.PySimpleApp()
49 frame
= MyFrame(None, "Simple wxPython App")