2015-08-28 63 views
2

嗨只是有一个问题捕捉实例时,用户输入一个字母,而不是数字。获取错误'不能分配数字到函数调用'pythonQt捕捉非整数输入

这是一个简单的两个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') 

回答

0

错误是在

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

的消息很简单 - 你不能分配数量函数调用。 (实际上,你不能分配任何东西给函数调用。)

还要注意,你可以将inputMaskvalidator分配给你的QLineEdit,你根本不需要检查无效输入。