2001-11-09 18:19:16 -05: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 19:13:10 -04:00
|
|
|
import wx # This module uses the new wx namespace
|
2003-11-12 16:34:20 -05:00
|
|
|
print "wx.VERSION_STRING = ", wx.VERSION_STRING
|
|
|
|
|
|
|
|
|
|
|
|
#import os; print os.getpid(); raw_input("press a key...")
|
2001-11-09 18:19:16 -05:00
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
class MyFrame(wx.Frame):
|
2002-01-05 18:45:33 -05:00
|
|
|
"""
|
2002-03-13 17:30:20 -05:00
|
|
|
This is MyFrame. It just shows a few controls on a wxPanel,
|
2002-01-05 18:45:33 -05:00
|
|
|
and has a simple menu.
|
|
|
|
"""
|
2001-11-09 18:19:16 -05:00
|
|
|
def __init__(self, parent, title):
|
2003-07-02 19:13:10 -04:00
|
|
|
wx.Frame.__init__(self, parent, -1, title, size=(350, 200))
|
2001-11-09 18:19:16 -05:00
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
menuBar = wx.MenuBar()
|
|
|
|
menu = wx.Menu()
|
2001-11-09 18:19:16 -05:00
|
|
|
menu.Append(101, "E&xit\tAlt-X", "Exit demo")
|
2003-07-02 19:13:10 -04:00
|
|
|
wx.EVT_MENU(self, 101, self.OnButton)
|
2001-11-09 18:19:16 -05:00
|
|
|
menuBar.Append(menu, "&File")
|
|
|
|
self.SetMenuBar(menuBar)
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
panel = wx.Panel(self, -1)
|
|
|
|
text = wx.StaticText(panel, -1, "Hello World!")
|
2003-10-01 19:28:31 -04:00
|
|
|
text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
|
2001-11-09 18:19:16 -05:00
|
|
|
text.SetSize(text.GetBestSize())
|
2003-07-02 19:13:10 -04:00
|
|
|
btn = wx.Button(panel, -1, "Close")
|
2001-11-09 18:19:16 -05:00
|
|
|
btn.SetDefault()
|
|
|
|
|
2003-10-01 19:28:31 -04:00
|
|
|
btn2 = wx.Button(panel, -1, "Just for fun...")
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
sizer.Add(text, 0, wx.ALL, 10)
|
|
|
|
sizer.Add(btn, 0, wx.ALL, 10)
|
2003-10-01 19:28:31 -04:00
|
|
|
sizer.Add(btn2, 0, wx.ALL, 10)
|
2001-11-09 18:19:16 -05:00
|
|
|
panel.SetSizer(sizer)
|
2003-03-25 01:35:27 -05:00
|
|
|
panel.SetAutoLayout(True)
|
2001-11-09 18:19:16 -05:00
|
|
|
panel.Layout()
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
wx.EVT_BUTTON(self, btn.GetId(), self.OnButton)
|
2003-10-01 19:28:31 -04:00
|
|
|
wx.EVT_BUTTON(self, btn2.GetId(), self.OnFunButton)
|
2001-11-09 18:19:16 -05:00
|
|
|
|
|
|
|
def OnButton(self, evt):
|
2002-01-05 18:45:33 -05:00
|
|
|
"""Event handler for the button click."""
|
2001-12-19 16:25:11 -05:00
|
|
|
print "OnButton"
|
2001-11-09 18:19:16 -05:00
|
|
|
self.Close()
|
|
|
|
|
2003-10-01 19:28:31 -04:00
|
|
|
def OnFunButton(self, evt):
|
|
|
|
"""Event handler for the button click."""
|
|
|
|
print "Having fun yet?"
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
app = wx.PySimpleApp()
|
2001-11-09 18:19:16 -05:00
|
|
|
frame = MyFrame(None, "Simple wxPython App")
|
2003-03-25 01:35:27 -05:00
|
|
|
frame.Show(True)
|
2001-11-09 18:19:16 -05:00
|
|
|
app.MainLoop()
|
|
|
|
|