报错
在PyQt5里创建的是MainWindow还是Widget?,如下图是两种不同窗口,创建的元素一定要调用正确。
创建的是Dialog
import sys from PyQt6 import QtWidgets from PyQt6.QtWidgets import QApplication, QDialog import Ui_SeismicPro if __name__ == '__main__': app = QApplication(sys.argv) MainWindow = QDialog() ui = Ui_SeismicPro.Ui_SeismicProgramme() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec())
创建的是MainWindow
import sys from PyQt6 import QtWidgets from PyQt6.QtWidgets import QApplication, QDialog import Ui_SeismicPro if __name__ == '__main__': app = QApplication(sys.argv) # MainWindow = QDialog() # ui = Ui_SeismicPro.Ui_SeismicProgramme() # 在pyqt中创建的是MainWindow,不是Widget或者dialog MainWindow=QtWidgets.QMainWindow() ui = Ui_SeismicPro.Ui_SeismicProgramme() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec())