2001-11-09 23:19:16 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# A very simple wxPython example. Just a wxFrame, wxPanel,
|
|
|
|
# wxStaticText, wxButton, and a wxBoxSizer, but it shows the basic
|
|
|
|
# structure of any wxPython application.
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
import wx # This module uses the new wx namespace
|
2001-11-09 23:19:16 +00:00
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
class MyFrame(wx.Frame):
|
2002-01-05 23:45:33 +00:00
|
|
|
"""
|
2002-03-13 22:30:20 +00:00
|
|
|
This is MyFrame. It just shows a few controls on a wxPanel,
|
2002-01-05 23:45:33 +00:00
|
|
|
and has a simple menu.
|
|
|
|
"""
|
2001-11-09 23:19:16 +00:00
|
|
|
def __init__(self, parent, title):
|
2003-07-02 23:13:10 +00:00
|
|
|
wx.Frame.__init__(self, parent, -1, title, size=(350, 200))
|
2001-11-09 23:19:16 +00:00
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
menuBar = wx.MenuBar()
|
|
|
|
menu = wx.Menu()
|
2001-11-09 23:19:16 +00:00
|
|
|
menu.Append(101, "E&xit\tAlt-X", "Exit demo")
|
2003-07-02 23:13:10 +00:00
|
|
|
wx.EVT_MENU(self, 101, self.OnButton)
|
2001-11-09 23:19:16 +00:00
|
|
|
menuBar.Append(menu, "&File")
|
|
|
|
self.SetMenuBar(menuBar)
|
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
panel = wx.Panel(self, -1)
|
|
|
|
text = wx.StaticText(panel, -1, "Hello World!")
|
|
|
|
text.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
|
2001-11-09 23:19:16 +00:00
|
|
|
text.SetSize(text.GetBestSize())
|
2003-07-02 23:13:10 +00:00
|
|
|
btn = wx.Button(panel, -1, "Close")
|
2001-11-09 23:19:16 +00:00
|
|
|
btn.SetDefault()
|
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
sizer.Add(text, 0, wx.ALL, 10)
|
|
|
|
sizer.Add(btn, 0, wx.ALL, 10)
|
2001-11-09 23:19:16 +00:00
|
|
|
panel.SetSizer(sizer)
|
2003-03-25 06:35:27 +00:00
|
|
|
panel.SetAutoLayout(True)
|
2001-11-09 23:19:16 +00:00
|
|
|
panel.Layout()
|
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
wx.EVT_BUTTON(self, btn.GetId(), self.OnButton)
|
2001-11-09 23:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def OnButton(self, evt):
|
2002-01-05 23:45:33 +00:00
|
|
|
"""Event handler for the button click."""
|
2001-12-19 21:25:11 +00:00
|
|
|
print "OnButton"
|
2001-11-09 23:19:16 +00:00
|
|
|
self.Close()
|
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
|
|
|
|
app = wx.PySimpleApp()
|
2001-11-09 23:19:16 +00:00
|
|
|
frame = MyFrame(None, "Simple wxPython App")
|
2003-03-25 06:35:27 +00:00
|
|
|
frame.Show(True)
|
2001-11-09 23:19:16 +00:00
|
|
|
app.MainLoop()
|
|
|
|
|