Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to launch a second GUI application via a button click in another GUI application - python



  • Using QT designer, I have created two GUI apps using pyqt5 that are currently working independently. However, I would like to execute the second GUI by clicking a pushbutton ('share') in the first GUI. Been hitting a lot of hurdles so far and will very much appreciate any help and pointer I can get to make a fix. Below, is the a code snippet for the second GUI that I want to run via the first GUI

    from PyQt5 import QtCore, QtGui, QtWidgets
    
    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
            MainWindow.setObjectName("MainWindow")
            MainWindow.setEnabled(True)
            MainWindow.resize(496, 474)
            self.centralwidget = QtWidgets.QWidget(MainWindow)
            self.centralwidget.setObjectName("centralwidget")
            self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
            self.scrollArea.setGeometry(QtCore.QRect(30, 30, 441, 401))
            self.scrollArea.setWidgetResizable(True)
            self.scrollArea.setObjectName("scrollArea")
            self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
            self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 439, 399))
            self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
            self.label_3 = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
            self.label_3.setGeometry(QtCore.QRect(20, 170, 71, 20))
            font = QtGui.QFont()
            font.setPointSize(12)
            self.label_3.setFont(font)
            self.label_3.setObjectName("label_3")
            self.pushButton = QtWidgets.QPushButton(self.scrollAreaWidgetContents_2)
            self.pushButton.setGeometry(QtCore.QRect(360, 160, 61, 31))
            font = QtGui.QFont()
            font.setPointSize(12)
            self.pushButton.setFont(font)
            self.pushButton.setObjectName("pushButton")
            self.pushButton_2 = QtWidgets.QPushButton(self.scrollAreaWidgetContents_2)
            self.pushButton_2.setGeometry(QtCore.QRect(340, 30, 71, 41))
            font = QtGui.QFont()
            font.setPointSize(12)
            self.pushButton_2.setFont(font)
            self.pushButton_2.setObjectName("pushButton_2")
            self.textEdit_3 = QtWidgets.QTextEdit(self.scrollAreaWidgetContents_2)
            self.textEdit_3.setGeometry(QtCore.QRect(100, 20, 231, 71))
            self.textEdit_3.setObjectName("textEdit_3")
            self.label_4 = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
            self.label_4.setGeometry(QtCore.QRect(10, 50, 81, 20))
            font = QtGui.QFont()
            font.setPointSize(12)
            self.label_4.setFont(font)
            self.label_4.setObjectName("label_4")
            self.pushButton_3 = QtWidgets.QPushButton(self.scrollAreaWidgetContents_2)
            self.pushButton_3.setGeometry(QtCore.QRect(180, 340, 101, 41))
            font = QtGui.QFont()
            font.setPointSize(12)
            self.pushButton_3.setFont(font)
            self.pushButton_3.setObjectName("pushButton_3")
            self.label_2 = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
            self.label_2.setGeometry(QtCore.QRect(170, 120, 91, 21))
            font = QtGui.QFont()
            font.setPointSize(12)
            self.label_2.setFont(font)
            self.label_2.setObjectName("label_2")
            self.line = QtWidgets.QFrame(self.scrollAreaWidgetContents_2)
            self.line.setGeometry(QtCore.QRect(70, 100, 301, 20))
            self.line.setFrameShape(QtWidgets.QFrame.HLine)
            self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
            self.line.setObjectName("line")
            self.textEdit = QtWidgets.QTextEdit(self.scrollAreaWidgetContents_2)
            self.textEdit.setGeometry(QtCore.QRect(100, 160, 251, 31))
            self.textEdit.setObjectName("textEdit")
            self.label_5 = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
            self.label_5.setGeometry(QtCore.QRect(10, 230, 101, 20))
            font = QtGui.QFont()
            font.setPointSize(12)
            self.label_5.setFont(font)
            self.label_5.setObjectName("label_5")
            self.textEdit_4 = QtWidgets.QTextEdit(self.scrollAreaWidgetContents_2)
            self.textEdit_4.setGeometry(QtCore.QRect(100, 220, 251, 31))
            self.textEdit_4.setObjectName("textEdit_4")
            self.pushButton_4 = QtWidgets.QPushButton(self.scrollAreaWidgetContents_2)
            self.pushButton_4.setGeometry(QtCore.QRect(360, 220, 61, 31))
            font = QtGui.QFont()
            font.setPointSize(12)
            self.pushButton_4.setFont(font)
            self.pushButton_4.setObjectName("pushButton_4")
            self.label = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
            self.label.setGeometry(QtCore.QRect(30, 300, 47, 20))
            font = QtGui.QFont()
            font.setPointSize(12)
            self.label.setFont(font)
            self.label.setObjectName("label")
            self.textEdit_2 = QtWidgets.QTextEdit(self.scrollAreaWidgetContents_2)
            self.textEdit_2.setGeometry(QtCore.QRect(100, 290, 321, 31))
            self.textEdit_2.setObjectName("textEdit_2")
            self.scrollArea.setWidget(self.scrollAreaWidgetContents_2)
            MainWindow.setCentralWidget(self.centralwidget)
            self.menubar = QtWidgets.QMenuBar(MainWindow)
            self.menubar.setGeometry(QtCore.QRect(0, 0, 496, 21))
            self.menubar.setObjectName("menubar")
            MainWindow.setMenuBar(self.menubar)
            self.statusbar = QtWidgets.QStatusBar(MainWindow)
            self.statusbar.setObjectName("statusbar")
            MainWindow.setStatusBar(self.statusbar)
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
    
        def retranslateUi(self, MainWindow):
            _translate = QtCore.QCoreApplication.translate
            MainWindow.setWindowTitle(_translate("MainWindow", "Send File"))
            self.label_3.setText(_translate("MainWindow", "+ File"))
            self.pushButton.setText(_translate("MainWindow", "Open"))
            self.pushButton_2.setText(_translate("MainWindow", "Convert"))
            self.textEdit_3.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>"))
            self.label_4.setText(_translate("MainWindow", "Paste Hash"))
            self.pushButton_3.setText(_translate("MainWindow", "Send"))
            self.label_2.setText(_translate("MainWindow", "Attachments"))
            self.label_5.setText(_translate("MainWindow", "+ File Hash"))
            self.pushButton_4.setText(_translate("MainWindow", "Open"))
            self.label.setText(_translate("MainWindow", "Email"))
    
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        MainWindow = QtWidgets.QMainWindow()
        ui = Ui_MainWindow()
        ui.setupUi(MainWindow)
        MainWindow.show()
        sys.exit(app.exec_())
    
    


  • @Stainopel
    None of this seems relevant. Either you don't really want separate applications but just one and you just want to show the other widget. Or, to run another application as you ask, use Qt's QProcess, or the Python ones for running sub-processes if you prefer, called from your button clicked slot.


Log in to reply