【问题标题】:How to rectify the python error: "icon object is not callable"?如何纠正python错误:“图标对象不可调用”?
【发布时间】:2017-05-24 08:20:44
【问题描述】:

我有一本字典,其中包含某些元素和关联的键。我想创建一个 GUI 来显示项目。我在 for 循环中使用了 QMessageBox PyQt 小部件。但是当我运行代码时出现以下错误:

回溯(最近一次调用最后):文件“C:\Python34_64bit\dictt.py”,第 50 行,在 main() 文件“C:\Python34_64bit\dictt.py”,第 45 行,在 main GUI=MYGUI() 文件“C:\Python34_64bit\dictt.py”,第 31 行,在 init self.Choice=QtGui.QMessageBox.Question(self,k,val,QtGui.QMes‌​sageBox.Yes | QtGui.QMessageBox.否) TypeError: 'Icon' 对象不可调用

请帮助我如何通过修改我的代码来解决此问题。以下是我的代码:

import sys
from PyQt4 import QtGui,QtCore

class MYGUI(QtGui.QWidget):

    def __init__(self):
        super(MYGUI,self).__init__()

        self.setWindowTitle("GUI")

        #widgets:

        self.labl=QtGui.QLabel(self)    
        self.labl.setFont(QtGui.QFont('Calibri', 34))


        #Layout:

        Layout =QtGui.QVBoxLayout()
        Layout.addWidget(self.labl)
        Layout.addStretch()
        self.setLayout(Layout)

        #Actions:                


        Queries={'Q1':'question 1','Q2':'question2'}

        for k,val in Queries.items():

            self.Choice=QtGui.QMessageBox.Question(self,k,val,QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)

            if choice==QtGui.QMessageBox.Yes:
                self.labl.setText('yes')

            else:
                self.labl.setText('No')

        self.show()


def main():

    app=QtGui.QApplication(sys.argv)
    GUI=MYGUI()

    sys.exit(app.exec_())


main()

【问题讨论】:

  • 您应该在问题中包含完整的错误跟踪,尤其是指出错误发生在哪一行的部分。
  • Traceback(最近一次调用最后):文件“C:\Python34_64bit\dictt.py”,第 50 行,在 main() 文件“C:\Python34_64bit\dictt.py”中,第 45 行,在主 GUI=MYGUI() 文件 "C:\Python34_64bit\dictt.py",第 31 行,在 init self.Choice=QtGui.QMessageBox.Question(self,k,val, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) TypeError: 'Icon' object is not callable
  • @pavansunder 在您的问题中;不是评论。

标签: python python-3.x pyqt4


【解决方案1】:

您的问题只是小写/大写。

QMessageBox.Question 是图标

QMessageBox.question(parent, title, text, button0, button1)是函数

见:https://srinikom.github.io/pyside-docs/PySide/QtGui/QMessageBox.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-21
    • 2012-12-06
    • 2020-06-24
    • 2014-06-13
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多