作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做一个测验,当有人答错问题时,我想告诉他们他们答错了,正确答案是什么。我从数据库中获取问题,并在每次按下下一个按钮时设置文本
print("You chose the incorrect answer the correct answer was" + (self.Correctanswer))
但是这会返回错误
print("You chose the incorrect answer the correct answer was" + (self.Correctanswer))
TypeError: Can't convert 'QRadioButton' object to str implicitly
我做了一些研究,我看到了这个方法
print("You chose the incorrect answer the correct answer was" + format(self.Correctanswer))
尽管这消除了错误,但它没有显示正确的答案
You chose the incorrect answer the correct answer was<PyQt4.QtGui.QRadioButton object at 0x0000000003EB4F78>
问题是我怎样才能让它在单选按钮中显示当前的正确答案。我设置单选按钮的方式是这样的
self.Correctanswer.setText(self.Questions[0][2])
最佳答案
您的单选按钮是一个对象。输出 <PyQt4.QtGui.QRadioButton object at 0x0000000003EB4F78>
表明了这一点.
正如您使用self.Correctanswer.setText()
一样,要设置其显示的文本,您必须使用类似的方法从此类对象接收文本。查看 PyQt4 文档中相应的函数,但我猜想类似 self.Correctanswer.getText()
将工作。通常是.setText()
和.getText()
,或.setValue()
和.getValue()
,或者类似的东西:-)
关于python - 类型错误:无法将 'QRadioButton' 对象隐式转换为 str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29329225/
我是一名优秀的程序员,十分优秀!