PyQT开发报错信息及解决方案

来源:互联网 发布:地图染色堆栈算法 编辑:程序博客网 时间:2024/06/01 14:54



1:

AttributeError: 'Window' object has no attribute 'setCentralWidget'

You need to inherit from QMainWindow, not QWidgetsetCentralWidget is a method of QMainWindow.

from PyQt4.QtCore import Qt, SIGNALfrom PyQt4.QtGui import *from ui_mainwindow import Ui_MainWindowclass Window(QMainWindow, Ui_MainWindow):    def __init__(self, parent = None):        QMainWindow.__init__(self, parent)        # or better        # super(Window, self).__init__(parent)        self.setupUi(self)
谷歌到的解决方案:原因很简单,setCentralWidget 是 QMainWindow 的类而不是 QWidget的类

0 0