我有一个文本框,它接受用户输入并检查输入是否正确。 如果输入不正确,我会创建一个对话框,要求用户再次输入信息,并用计数说明剩余的尝试次数。但是,对话框一直在倒计时,不允许用户输入任何数据。在
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
如何使循环暂停,直到用户重新输入用户和密码,然后再继续?在
循环只是不断地创建消息对话框,而不是让用户做一些事情。您需要移除循环并将计数器放在事件处理程序之外。下面是一个可运行的示例:
相关问题 更多 >
编程相关推荐