Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Change UI within same window PyQt

# consider QStackedLayout as well

import os
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic

ui_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_())
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Change #UI #window #PyQt
ADD COMMENT
Topic
Name
9+9 =