Replacing the existing MainWindow with a new window with Python, PyQt, Qt Designer
<p>I'm new to Python GUI programming I'm have trouble making a GUI app. I have a main window with only a button widget on it. What i want to know is how to replace the existing window with a new window when an event occurs (such as a button click).<br>
An answer to a similar question here <a href="http://stackoverflow.com/questions/13550076/replace-centralwidget-in-mainwindow">Replace CentralWidget in MainWindow</a>, suggests using QStackedWidgets but they did not use Qt Designer to make their GUI apps whereas I have two .py files, one is the main window file and the other of window that i want to show after a button press take place, hence i don't know how to combine these two in my main.py file.
For Example my main window looks like this:<br>
<a href="http://i.stack.imgur.com/soSsW.png" rel="nofollow"><img src="http://i.stack.imgur.com/soSsW.png" alt="Main Window"></a><br>
And after clicking on the button it should replace the existing window with this:<br>
<a href="http://i.stack.imgur.com/jmgk4.png" rel="nofollow"><img src="http://i.stack.imgur.com/jmgk4.png" alt="New Window"></a><br>
I would also like to know if the second window should be of type QStackedWindow, QDialog or QWidget?<br>
Here is my main.py code  </p>

<pre><code>from PyQt4 import QtGui
import sys
import design, design1
import os

class ExampleApp(QtGui.QMainWindow, design.Ui_MainWindow):
    def __init__(self, parent=None):
        super(ExampleApp, self).__init__(parent)
        self.setupUi(self)
        self.btnBrowse.clicked.connect(self.doSomething)


    def doSomething(self):
        # Code to replace the main window with a new window
        pass


def main():
    app = QtGui.QApplication(sys.argv)
    form = ExampleApp()
    form.show()
    app.exec_()


if __name__ == '__main__':
    main()
</code></pre>

<p>You can use the QStackedWindow to create a entire new window and hten connect it to the main window through onclick() event.</p>

<pre><code>button.clicked.connect(self.OtherWindow)
</code></pre>

<p>Or else you can simply use the</p>

<pre><code>class OtherWindow(self):
    Owindow = OtherWindow()  
    Owindow.show()

def main():
    app = QtGui.QApplication(sys.argv)
    form = ExampleApp()
    form.show()
    app.exec_()


if __name__ == '__main__':
    main()
</code></pre>

python pyqt qt-designer