【发布时间】:2014-05-13 18:27:39
【问题描述】:
我有一个文本框,它接收用户输入并检查输入是否正确。 如果输入不正确,我制作了一个对话框,要求用户再次输入信息,并用计数说明剩余的尝试次数。但是对话框一直倒计时,不允许用户输入任何数据。
def OnClick2(self,event):
password=self.enteredPass.GetValue() #takes the password form the textbox
user=self.enteredUser.GetValue() #takes the username form the textbox
count=0 # count for the number of tries
while (user!="Username" and password!="Password"): #loops untill it is right
dlg=wx.MessageDialog(self,"You have %s tries left"%(str(3-count)),"",wx.OK)
dlg.ShowModal()
dlg.Destroy()
count=count+1
password=self.enteredPass.GetValue() #retakes the password
user=self.enteredUser.GetValue() #retakes the username
if (count==3):
self.Destroy()
break
我怎样才能让循环暂停,直到用户重新输入用户和密码,然后再继续?
【问题讨论】:
-
为什么在 'if' 中有那个 'while' 循环?
-
我正在重新考虑 if 语句,但是 while 循环可以提示一个对话框,告诉用户输入的数据错误并显示剩余的尝试次数
-
我是说我不明白为什么“如果”部分存在。
-
好吧,我把 if 语句去掉了