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 メソッドの何が問題になっていますか?