首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pythonQt捕获非整数输入

pythonQt捕获非整数输入
EN

Stack Overflow用户
提问于 2015-08-28 11:25:00
回答 1查看 57关注 0票数 2

当用户输入字母而不是数字时,我们只是在捕获实例时遇到问题。Get错误‘无法将编号分配给函数调用’

这是一个简单的两个QLine编辑框,其中用户必须猜测number...any帮助将不胜感激。我刚刚发布了函数位

代码语言:javascript
复制
 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')
EN

回答 1

Stack Overflow用户

发布于 2015-08-28 19:26:37

错误在

代码语言:javascript
复制
reply.text()= int(reply.text())

这条信息很简单--你不能给函数调用分配编号。(实际上,您不能将任何内容分配给函数调用。)

还要注意的是,您可以将inputMaskvalidator赋值给您的QLineEdit,并且根本不需要检查无效输入。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32262857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档