pythonQt捕捉非整数输入

  • 本文关键字:整数 pythonQt python
  • 更新时间 :
  • 英文 :


我们只是在捕捉用户输入字母而不是数字的实例时遇到了问题。获取错误'can't assign number to function call'

这是一个简单的两个QLine编辑框,用户必须猜测数字…任何帮助都会很感激。刚刚发布了函数位

 def my_response():
        global counter, random_number
        timer=QtCore.QTimer
        try:
            reply.text()= int(reply.text())
            if int(reply.text()) <self. random_number:
                question.setText("Your guess is too low. Please Try Again")
                reply.setText(" ")

            elif int(reply.text()) >self. random_number:
                question.setText("Your guess is too high. Please Try Again")
                reply.setText(" ")

            elif int(reply.text()) ==self. random_number:
                question.setStyleSheet('QLineEdit{color: blue}')
                question.setFont(QtGui.QFont("Stencil", 15, QtGui.QFont.Bold))
                question.setText("Correct")
                timer.singleShot(250,lambda:question.setText('You won'))
                reply.setText(" ")
        except:
            reply.setText('invalad input number is needed')

Error is at

reply.text()= int(reply.text())

消息很简单-你不能给函数调用分配number。(实际上,你不能给函数调用赋值)

还请注意,您可以将inputMaskvalidator分配给QLineEdit,并且您根本不必检查无效输入

最新更新