0

大家好,我正在学习 python 语言,而对于 gui,我使用 wxpython。我的 GUI 中有 2 个旋转 ctrl、1 个文本 ctrl、1 个密码 ctrl。每当用户输入错误的密码时,它会弹出“密码错误”的消息。然后用户再次输入密码,但发生的情况是密码字段用“2 spin ctrl, and 1 text ctrl”重置,我想在用户输入错误密码时保留 spinctrl 和 textctrl 的值,消息框将显示 -向上。如何做到这一点?请给我建议。

  class child(wx.Frame):    
  self.sc1 = wx.SpinCtrl(self,-1, pos=(-1, -1))
  self.paswd = wxTextCtrl(self, -1, (-1, -1),(30,20))
  def main(self, event):
  lan1 = self.sc1.GetValue()
  password = self.paswd.GetValue()
  if lan1 > 16 :
     wx.MessageBox("zzzzzzzzzzzz","warning")
     if password = license(hard coded):
        """show message box 
        and install"""
     else:
        """re enter password"""
        Child().Show()
   //when child window again pop up spin ctrl also set to 0, i want to keep spin ctrl value when user enter wrong password.     
4

1 回答 1

0

你应该发布你已经拥有的东西,这样我们就可以看到你哪里出错了。知道您正在使用哪个版本的 wxPython 和 Python 以及哪个操作系统也会很好。无论如何,这是一种方法:

import wx

########################################################################
class LoginPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        userSizer = wx.BoxSizer(wx.HORIZONTAL)
        pwdSizer = wx.BoxSizer(wx.HORIZONTAL)

        userLbl = wx.StaticText(self, label="Username:")
        userSizer.Add(userLbl, 0, wx.CENTER|wx.ALL, 5)
        self.userTxt = wx.TextCtrl(self)
        userSizer.Add(self.userTxt, 1, wx.EXPAND|wx.ALL, 5)

        pwdLbl = wx.StaticText(self, label="Password:")
        pwdSizer.Add(pwdLbl, 0, wx.CENTER|wx.ALL, 5)
        self.pwdTxt = wx.TextCtrl(self, style=wx.TE_PASSWORD)
        pwdSizer.Add(self.pwdTxt, 1, wx.EXPAND|wx.ALL, 5)

        loginBtn = wx.Button(self, label="Login") 
        loginBtn.Bind(wx.EVT_BUTTON, self.onLogin)

        self.mainSizer.Add(userSizer, 0, wx.EXPAND)
        self.mainSizer.Add(pwdSizer, 0, wx.EXPAND)
        self.mainSizer.Add(loginBtn, 0, wx.CENTER|wx.ALL, 5)
        self.SetSizer(self.mainSizer)

    #----------------------------------------------------------------------
    def onLogin(self, event):
        """
        Login or show msg box if password wrong
        """
        username = self.userTxt.GetValue()
        pwd = self.pwdTxt.GetValue()

        if pwd == "password":
            print "logging in"
        else:
            msg = "Wrong password or username!"
            wx.MessageBox(msg, "Error", wx.OK|wx.ICON_INFORMATION)


########################################################################
class LoginFrame(wx.Frame):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Login")
        panel = LoginPanel(self)
        self.Show()

if __name__ == "__main__":
    app = wx.App(False)
    frame = LoginFrame()
    app.MainLoop()
于 2013-05-07T16:13:54.813 回答