我已经构建了一个 wxTextCtrl 并希望在用户仅输入数字时返回 true。
这是我的 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 方法有什么问题?