TypeError: Can't convert 'QRadioButton' object to str implicitly
TypeError: Can't convert 'QRadioButton' object to str implicitly
我正在做一个测验,当有人答错问题时,我想告诉他们他们答错了,正确答案是什么。我从数据库中获取我的问题并在每次按下下一个按钮时设置文本
print("You chose the incorrect answer the correct answer was" + (self.Correctanswer))
然而这个returns错误
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()
,或者像这样的东西:-)
我正在做一个测验,当有人答错问题时,我想告诉他们他们答错了,正确答案是什么。我从数据库中获取我的问题并在每次按下下一个按钮时设置文本
print("You chose the incorrect answer the correct answer was" + (self.Correctanswer))
然而这个returns错误
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()
,或者像这样的东西:-)