self.tilte=wx.StaticText(panel,label="请输入用户名和密码") self.label_user=wx.StaticText(panel,label="用户名:") self.text_user=wx.TextCtrl(panel,style=wx.TE_LEFT) self.label_pwd=wx.StaticText(panel,label="密 码:") self.text_password=wx.TextCtrl(panel,style=wx.TE_PASSWORD)
hsizer_user =wx.BoxSizer(wx.HORIZONTAL) hsizer_user.Add(self.label_user,proportion=0,flag=wx.ALL,border=5) hsizer_user.Add(self.text_user,proportion=1,flag=wx.ALL,border=5) hsizer_pwd=wx.BoxSizer(wx.HORIZONTAL) hsizer_pwd.Add(self.label_pwd,proportion=0,flag=wx.ALL,border=5) hsizer_pwd.Add(self.text_password,proportion=1,flag=wx.ALL,border=5) hsizer_button=wx.BoxSizer(wx.HORIZONTAL) hsizer_button.Add(self.bt_confirm,proportion=0,flag=wx.ALIGN_CENTER,border=5) hsizer_button.Add(self.bt_cancel,proportion=0,flag=wx.ALIGN_CENTER,border=5) vsizer_all=wx.BoxSizer(wx.VERTICAL) vsizer_all.Add(self.tilte,proportion=0,flag=wx.BOTTOM|wx.Top|wx.ALIGN_CENTER,border=15) vsizer_all.Add(hsizer_user,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45) vsizer_all.Add(hsizer_pwd,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45) vsizer_all.Add(hsizer_button,proportion=0,flag=wx.ALIGN_CENTER|wx.Top,border=15) panel.SetSizer(vsizer_all)
def OnclickSubmit(self,event): message="" username=self.text_user.GetValue() password=self.text_password.GetValue() if username==""or password=="": message='用户名和密码不能为空' elif username=='小白' and password=='123456': message='登陆成功' else: message='用户名与密码不匹配' wx.MessageBox(message) def OnclickCancel(self,event): self.text_user.SetValue("") self.text_password.SetValue("") if __name__=='__main__': app=wx.App() frame=MyFrame(parent=None,id=-1) frame.Show() app.MainLoop()