pyqt问题:TypeError: 'sip.methoddescriptor' object is not callable
用pyqt4的qt设计师做了个主窗口,然后放了个按钮,弄了个槽:点按钮后,窗口退出
然后:pyuic4 -o test.py test.ui
写了个测试脚本:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
import test2
class TestDlg(QDialog, test2.Ui_MainWindow):
def __init__(self, parent=None):
super(TestDlg, self).__init__(parent)
self.setupUi(self)
app = QApplication(sys.argv)
dialog = TestDlg()
dialog.show()
执行报错:
Traceback (most recent call last):
File "F:\Python26\Lib\site-packages\PyQt4\test919.py", line 11, in <module>
dialog = TestDlg()
File "F:\Python26\Lib\site-packages\PyQt4\test919.py", line 9, in __init__
self.setupUi(self)
File "F:\Python26\Lib\site-packages\PyQt4\test2.py", line 26, in setupUi
MainWindow.setCentralWidget(self.centralwidget)
TypeError: 'sip.methoddescriptor' object is not callable
test.py 的内容是:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test2.ui'
#
# Created: Fri Sep 21 12:52:53 2012
# by: PyQt4 UI code generator 4.9.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(195, 69)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(50, 10, 75, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 195, 17))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.deleteLater)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
【注明】老是提示:TypeError: 'sip.methoddescriptor' object is not callable,这是个什么东东?
[解决办法]
测试脚本写得。。。
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QWidget
import sys
import test2
class TestDlg(QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self , parent)
self.ui = test2.Ui_MainWindow()
self.setupUi(self)
app = QApplication(sys.argv)
dialog = TestDlg()
dialog.show()
sys.exit(app.exec_())