我希望我的 StaticTexts 和 TextCtrls 像这样对齐:http: //i.stack.imgur.com/llE7F.png
所以我这样做了:
import wx
class LoginForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,wx.ID_ANY,title='Login',size=(800,600))
self.panel = wx.Panel(self,wx.ID_ANY)
email_label = wx.StaticText(self.panel,wx.ID_ANY,'Email: ')
pass_label = wx.StaticText(self.panel,wx.ID_ANY,'Password: ')
email = wx.TextCtrl(self.panel,wx.ID_ANY,'',size=(150,-1))
passwd = wx.TextCtrl(self.panel,wx.ID_ANY,'',size=(150,-1))
loginBtn = wx.Button(self.panel,wx.ID_ANY,'Login')
self.Bind(wx.EVT_BUTTON,self.onLogin,loginBtn)
topSizer = wx.BoxSizer(wx.VERTICAL)
labelSizer = wx.BoxSizer(wx.HORIZONTAL)
inputSizer = wx.BoxSizer(wx.HORIZONTAL)
labelSizer.Add(email_label,0,wx.RIGHT,112)
labelSizer.Add(pass_label,0,wx.RIGHT,177)
inputSizer.Add(email,0,wx.RIGHT,5)
inputSizer.Add(passwd,0,wx.RIGHT,5)
inputSizer.Add(loginBtn,0,wx.RIGHT,10)
topSizer.Add(labelSizer,0,wx.TOP|wx.ALIGN_RIGHT,0)
topSizer.Add(inputSizer,0,wx.TOP|wx.ALIGN_RIGHT,0)
self.panel.SetSizer(topSizer)
def onLogin(self):
pass
if __name__=='__main__':
app = wx.App()
frame = LoginForm().Show()
app.MainLoop()
这是正确的方法吗?玩对齐标志和边框值?或者还有另一种方法可以做到这一点?
我这样做的方式,如果我想改变,例如登录按钮的宽度,一切都会搞砸