#!/usr/bin/python
# -*- coding: UTF-8 -*-
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "个人信息表单")
panel = wx.Panel(self)
# First create the controls
topLbl = wx.StaticText(panel, -1, "账户信息")
topLbl.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
nameLbl = wx.StaticText(panel, -1, "姓名:")
name = wx.TextCtrl(panel, -1, "");
addrLbl = wx.StaticText(panel, -1, "地址:")
addr1 = wx.TextCtrl(panel, -1, "");
addr2 = wx.TextCtrl(panel, -1, "");
cstLbl = wx.StaticText(panel, -1, "省, 市, 街道:")
city = wx.TextCtrl(panel, -1, "", size=(150, -1));
state = wx.TextCtrl(panel, -1, "", size=(50, -1));
zipcd = wx.TextCtrl(panel, -1, "", size=(70, -1));
phoneLbl = wx.StaticText(panel, -1, "电话:")
phone = wx.TextCtrl(panel, -1, "");
emailLbl = wx.StaticText(panel, -1, "Email:")
email = wx.TextCtrl(panel, -1, "");
saveBtn = wx.Button(panel, -1, "保存")
cancelBtn = wx.Button(panel, -1, "取消")
# 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(zipcd)
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)
# Finally, tell the panel to use the sizer for layout
panel.SetSizer(mainSizer)
# Give the frame a sizer too
sizer = wx.BoxSizer()
sizer.Add(panel, 1, wx.EXPAND)
self.SetSizer(sizer)
# 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.
self.Fit()
self.SetMinSize(self.GetSize())
app = wx.App()
TestFrame().Show()
app.MainLoop()