PyQt4 trouble creating a simple GUI application

后端 未结 1 1173
刺人心
刺人心 2021-02-20 09:54

so I\'m creating a simple windows application with Python and PyQt4. I\'ve designed my UI the way I want it in QtCreator and I\'ve created the necessary .py file from the .ui fi

1条回答
  •  滥情空心
    2021-02-20 10:25

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

    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)
    

    0 讨论(0)
提交回复
热议问题