Opening a window from another window in python using pyqt framework
Question: I am trying open a pyqt window from another pyqt window on clicking a button
but i can't really get a hold do it . Both the python files opening.py and
signup.py can run standalone on their own but i can't think of a way to link
them ...(Running signup.py from opening.py after clicking signup button)

opening.py

    
    
    # -*- coding: utf-8 -*-
    
    # Form implementation generated from reading ui file 'opening.ui'
    #
    # Created: Tue Jan 20 00:19:45 2015
    #      by: PyQt4 UI code generator 4.10.4
    #
    # WARNING! All changes made in this file will be lost!
    
    from PyQt4 import QtCore, QtGui
    #from signup import Ui_Dialog1
    
    try:
        _fromUtf8 = QtCore.QString.fromUtf8
    except AttributeError:
        def _fromUtf8(s):
            return s
    
    try:
        _encoding = QtGui.QApplication.UnicodeUTF8
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig,     _encoding)
    except AttributeError:
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig)
    
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName(_fromUtf8("Dialog"))
            Dialog.resize(290, 237)
            self.label = QtGui.QLabel(Dialog)
            self.label.setGeometry(QtCore.QRect(70, 19, 151, 41))
            self.label.setObjectName(_fromUtf8("label"))
            self.pushButton = QtGui.QPushButton(Dialog)
            self.pushButton.setGeometry(QtCore.QRect(40, 170, 201, 41))
            self.pushButton.setObjectName(_fromUtf8("pushButton"))
            self.pushButton_2 = QtGui.QPushButton(Dialog)
            self.pushButton_2.setGeometry(QtCore.QRect(40, 100, 201, 41))
            self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
            self.pushButton.clicked.connect(self.handleTest1)
            self.pushButton_2.clicked.connect(self.handleTest2)
    
            self.retranslateUi(Dialog)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
    
        def retranslateUi(self, Dialog):
            Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
            self.label.setText(_translate("Dialog", "MAIL SERVER", None))
            self.pushButton.setText(_translate("Dialog", "SIGN UP", None))
            self.pushButton_2.setText(_translate("Dialog", "LOGIN", None))
    
        def handleTest1(self):
    
            #self.accept()       
            #self.h=Ui_Dialog1()
            #self.h.setupUi(QtGui.QDialog())        
            pass
    
        def handleTest2(self):
            execfile('login.py')
    
    import sys
    
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        Dialog = QtGui.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        sys.exit(app.exec_())
    

and other file which is to be opened after clicking signup button (login
button doesn't work as of now)

signup.py

    
    
    # -*- coding: utf-8 -*-
    
    # Form implementation generated from reading ui file 'abc.ui'
    #
    # Created: Mon Jan 19 23:35:37 2015
    #      by: PyQt4 UI code generator 4.10.4
    #
    # WARNING! All changes made in this file will be lost!
    
    from PyQt4 import QtCore, QtGui
    
    
    try:
        _fromUtf8 = QtCore.QString.fromUtf8
    except AttributeError:
        def _fromUtf8(s):
            return s
    
    try:
        _encoding = QtGui.QApplication.UnicodeUTF8
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig, _encoding)
    
    
    except AttributeError:
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig)
    
    
    class Ui_Dialog1(object):
        def setupUi(self, Dialog):
            print "16"        
    
            Dialog.setObjectName(_fromUtf8("SignUp"))
            Dialog.resize(415, 364)
            self.SignUp = QtGui.QDialogButtonBox(Dialog)
            self.SignUp.setGeometry(QtCore.QRect(130, 310, 176, 27))
            self.SignUp.setOrientation(QtCore.Qt.Horizontal)
            self.SignUp.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)  
            self.SignUp.setObjectName(_fromUtf8("SignUp"))
            self.label = QtGui.QLabel(Dialog)
            self.label.setGeometry(QtCore.QRect(50, 50, 91, 21))
            self.label.setObjectName(_fromUtf8("label"))
            self.label_2 = QtGui.QLabel(Dialog)
            self.label_2.setGeometry(QtCore.QRect(50, 110, 66, 17))
            self.label_2.setText(_fromUtf8(""))
            self.label_2.setObjectName(_fromUtf8("label_2"))
            self.label_3 = QtGui.QLabel(Dialog)
            self.label_3.setGeometry(QtCore.QRect(50, 100, 66, 17))
            self.label_3.setObjectName(_fromUtf8("label_3"))
            self.label_4 = QtGui.QLabel(Dialog)
            self.label_4.setGeometry(QtCore.QRect(50, 150, 66, 17))
            self.label_4.setObjectName(_fromUtf8("label_4"))
            self.label_5 = QtGui.QLabel(Dialog)
            self.label_5.setGeometry(QtCore.QRect(50, 200, 121, 17))
            self.label_5.setObjectName(_fromUtf8("label_5"))
            self.label_6 = QtGui.QLabel(Dialog)
            self.label_6.setGeometry(QtCore.QRect(50, 250, 91, 17))
            self.label_6.setObjectName(_fromUtf8("label_6"))
            self.lineEdit_3 = QtGui.QLineEdit(Dialog)
            self.lineEdit_3.setGeometry(QtCore.QRect(200, 140, 181, 27))
            self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
            self.lineEdit_4 = QtGui.QLineEdit(Dialog)
            self.lineEdit_4.setGeometry(QtCore.QRect(200, 190, 181, 27))
            self.lineEdit_4.setObjectName(_fromUtf8("lineEdit_4"))
            self.lineEdit_5 = QtGui.QLineEdit(Dialog)
            self.lineEdit_5.setGeometry(QtCore.QRect(200, 90, 181, 27))
            self.lineEdit_5.setObjectName(_fromUtf8("lineEdit_5"))
            self.lineEdit_6 = QtGui.QLineEdit(Dialog)
            self.lineEdit_6.setGeometry(QtCore.QRect(200, 40, 181, 27))
            self.lineEdit_6.setObjectName(_fromUtf8("lineEdit_6"))
            self.lineEdit_7 = QtGui.QLineEdit(Dialog)
            self.lineEdit_7.setGeometry(QtCore.QRect(200, 240, 181, 27))
            self.lineEdit_7.setObjectName(_fromUtf8("lineEdit_7"))
    
            self.retranslateUi(Dialog)
            QtCore.QObject.connect(self.SignUp, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept)
            QtCore.QObject.connect(self.SignUp, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
            print "17"
            Dialog.show()
    
        def retranslateUi(self, Dialog):
            Dialog.setWindowTitle(_translate("SignUp", "SignUp", None))
            self.label.setText(_translate("Dialog", "Name", None))
            self.label_3.setText(_translate("Dialog", "E-mail", None))
            self.label_4.setText(_translate("Dialog", "Password", None))
            self.label_5.setText(_translate("Dialog", "Confirm Password", None))
            self.label_6.setText(_translate("Dialog", "Mobile (+91)", None))
    
    
    if __name__ == "__main__":
        import sys
        app = QtGui.QApplication(sys.argv)
        Dialog = QtGui.QDialog()
        ui = Ui_Dialog1()
        ui.setupUi(Dialog)
        Dialog.show()
        sys.exit(app.exec_())
    

The commented part in opening.py is the one creating problems . Help would be
appreciated .


Answer: Your Ui_Dialog1 should inherit from QDialog, which makes it an UI object, but
you inherit from object, this has no "show" method.

    
    
    def handleTest1(self):
    
            #self.accept()
            #self.h=Ui_Dialog1()     # You need to move this to __init__ function
            #self.h.setupUi(QtGui.QDialog()) # You need to move this to __init__ function
            self.h.show()  # call the show method here
    

You need to move the self.h = Ui_Dialog1() and setupUi to **init** functions,
this will avoid possible memory leak. (otherwise each time you click
"sigunup", it will create a new object)

