96 lines
3.3 KiB
Python
96 lines
3.3 KiB
Python
|
import wx
|
||
|
|
||
|
class TestFrame(wx.Frame):
|
||
|
def __init__(self):
|
||
|
wx.Frame.__init__(self, None, -1, "Real World Test")
|
||
|
panel = wx.Panel(self)
|
||
|
|
||
|
# First create the controls
|
||
|
topLbl = wx.StaticText(panel, -1, "Account Information")
|
||
|
topLbl.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
|
||
|
|
||
|
nameLbl = wx.StaticText(panel, -1, "Name:")
|
||
|
name = wx.TextCtrl(panel, -1, "");
|
||
|
|
||
|
addrLbl = wx.StaticText(panel, -1, "Address:")
|
||
|
addr1 = wx.TextCtrl(panel, -1, "");
|
||
|
addr2 = wx.TextCtrl(panel, -1, "");
|
||
|
|
||
|
cstLbl = wx.StaticText(panel, -1, "City, State, Zip:")
|
||
|
city = wx.TextCtrl(panel, -1, "", size=(150,-1));
|
||
|
state = wx.TextCtrl(panel, -1, "", size=(50,-1));
|
||
|
zip = wx.TextCtrl(panel, -1, "", size=(70,-1));
|
||
|
|
||
|
phoneLbl = wx.StaticText(panel, -1, "Phone:")
|
||
|
phone = wx.TextCtrl(panel, -1, "");
|
||
|
|
||
|
emailLbl = wx.StaticText(panel, -1, "Email:")
|
||
|
email = wx.TextCtrl(panel, -1, "");
|
||
|
|
||
|
saveBtn = wx.Button(panel, -1, "Save")
|
||
|
cancelBtn = wx.Button(panel, -1, "Cancel")
|
||
|
|
||
|
# Now do the layout.
|
||
|
|
||
|
# mainSizer is the top-level one that manages everything
|
||
|
mainSizer = wx.BoxSizer(wx.VERTICAL)
|
||
|
mainSizer.Add(topLbl, 0, wx.ALL, 5)
|
||
|
mainSizer.Add(wx.StaticLine(panel), 0,
|
||
|
wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||
|
|
||
|
# addrSizer is a grid that holds all of the address info
|
||
|
addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
|
||
|
addrSizer.AddGrowableCol(1)
|
||
|
addrSizer.Add(nameLbl, 0,
|
||
|
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
|
||
|
addrSizer.Add(name, 0, wx.EXPAND)
|
||
|
addrSizer.Add(addrLbl, 0,
|
||
|
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
|
||
|
addrSizer.Add(addr1, 0, wx.EXPAND)
|
||
|
addrSizer.Add((10,10)) # some empty space
|
||
|
addrSizer.Add(addr2, 0, wx.EXPAND)
|
||
|
|
||
|
addrSizer.Add(cstLbl, 0,
|
||
|
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
|
||
|
|
||
|
# the city, state, zip fields are in a sub-sizer
|
||
|
cstSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||
|
cstSizer.Add(city, 1)
|
||
|
cstSizer.Add(state, 0, wx.LEFT|wx.RIGHT, 5)
|
||
|
cstSizer.Add(zip)
|
||
|
addrSizer.Add(cstSizer, 0, wx.EXPAND)
|
||
|
|
||
|
addrSizer.Add(phoneLbl, 0,
|
||
|
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
|
||
|
addrSizer.Add(phone, 0, wx.EXPAND)
|
||
|
addrSizer.Add(emailLbl, 0,
|
||
|
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
|
||
|
addrSizer.Add(email, 0, wx.EXPAND)
|
||
|
|
||
|
# now add the addrSizer to the mainSizer
|
||
|
mainSizer.Add(addrSizer, 0, wx.EXPAND|wx.ALL, 10)
|
||
|
|
||
|
# The buttons sizer will put them in a row with resizeable
|
||
|
# gaps between and on either side of the buttons
|
||
|
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||
|
btnSizer.Add((20,20), 1)
|
||
|
btnSizer.Add(saveBtn)
|
||
|
btnSizer.Add((20,20), 1)
|
||
|
btnSizer.Add(cancelBtn)
|
||
|
btnSizer.Add((20,20), 1)
|
||
|
|
||
|
mainSizer.Add(btnSizer, 0, wx.EXPAND|wx.BOTTOM, 10)
|
||
|
|
||
|
panel.SetSizer(mainSizer)
|
||
|
|
||
|
# Fit the frame to the needs of the sizer. The frame will
|
||
|
# automatically resize the panel as needed. Also prevent the
|
||
|
# frame from getting smaller than this size.
|
||
|
mainSizer.Fit(self)
|
||
|
mainSizer.SetSizeHints(self)
|
||
|
|
||
|
|
||
|
app = wx.PySimpleApp()
|
||
|
TestFrame().Show()
|
||
|
app.MainLoop()
|