我已經構建了一個wxTextCtrl並希望返回true,如果只有用戶輸入的數字。wxTextCtrl代碼來檢測只有在Python中的數字
這裏是我的Python代碼:
@staticmethod
def isAllDigits(s):
for char in list(s):
if not char.isdigit():
return False
else:
break
return True
而且我的代碼調用isAllDigits:
if self.firstNum.IsEmpty() or not self.isAllDigits(self.firstNum.GetValue()):
self.dataInputIsValid = False
msgStr = "Your first number is invalid, please enter only enter digits and do not leave the field blank."
wx.MessageBox(msgStr)
if self.secondNum.IsEmpty() or not self.isAllDigits(self.secondNum.GetValue()):
self.dataInputIsValid = False
msgStr = "Your second number is invalid, please enter only enter digits and do not leave the field blank."
wx.MessageBox(msgStr)
出於某種原因,我isAllDigits方法並不只檢測數字。例如,如果我要在textCtrl中輸入「3k5」,我的程序將返回「3k5」是全部數字並且是有效的,這是不正確的。
我的isAllDigits方法有什麼問題?
刪除else break – 2014-09-22 03:27:53