1:
AttributeError: 'Window' object has no attribute 'setCentralWidget'
You need to inherit from
QMainWindow
, notQWidget
.setCentralWidget
is a method ofQMainWindow
.谷歌到的解决方案:原因很简单,from PyQt4.QtCore import Qt, SIGNAL from PyQt4.QtGui import * from ui_mainwindow import Ui_MainWindow class 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的类