如何使用PyQt5在同一窗口中更改UI?

如何使用PyQt5在同一窗口中更改UI?,第1张

如何使用PyQt5在同一窗口中更改UI?

您必须使用

QStackedWidget

import osimport sysfrom PyQt5 import QtCore, QtGui, QtWidgets, uicui_folder = os.path.join("frontend", "ui")about_company_ui, _ = uic.loadUiType(os.path.join(ui_folder, "about_company.ui"))intern_placement_ui, _ = uic.loadUiType(os.path.join(ui_folder, "intern_placement.ui"))class InternPlacement(QtWidgets.QMainWindow, intern_placement_ui):    def __init__(self, parent=None):        super(InternPlacement, self).__init__(parent)        self.setupUi(self)class aboutCompany(QtWidgets.QMainWindow, about_company_ui):    def __init__(self, parent=None):        super(aboutCompany, self).__init__(parent)        self.setupUi(self)if __name__ == "__main__":    app = QtWidgets.QApplication(sys.argv)    intern_window = InternPlacement()    about_window = aboutCompany()    w = QtWidgets.QStackedWidget()    w.addWidget(intern_window)    w.addWidget(about_window)    intern_window.intern_pushButton.clicked.connect(lambda: w.setCurrentIndex(1))    w.resize(640, 480)    w.show()    sys.exit(app.exec_())


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5431501.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存