如何纠正python错误:“图标对象不可调用”?

时间:2017-05-24 08:20:45

标签: python python-3.x pyqt4

我有一个字典,其中有某些元素和相关的键。我想创建一个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()

1 个答案:

答案 0 :(得分:3)

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

import { mount } from 'avoriaz'; import { expect } from 'chai'; import sinon from 'sinon'; import UploadFormFactory from '!!vue-loader?inject!@/components/UploadForm'; describe('upload', () => { it('passes form data to api.uploadFile', () => { const api = { uploadFile: sinon.spy() }; const UploadForm = UploadFormFactory({ '@/lib/api': api }) const testFormData = { test: 'test' }; const api = { uploadFile: sinon.spy() }; const wrapper = mount(UploadForm); wrapper.vm.upload(testFormData); expect(api.uploadFile.called).to.equal(true); }); }); 是图标

QMessageBox.Question是函数

请参阅:https://srinikom.github.io/pyside-docs/PySide/QtGui/QMessageBox.html