title: PyQt5 switch between windows
body: <p>I want to create menu based on tiles. Now I need PyQt5 concept how to switch MainWindow to Window1/Window2/... with back option to MainWindow. The only thing I've achieved is opening a new window on top. I'd rather have separate windows, where I could define different functions.</p>
  <pre class="lang-py prettyprint-override"><code>from PyQt5 import QtGui
  from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
  from PyQt5.QtCore import pyqtSlot
  import sys
  
  class Window(QMainWindow):
      def __init__(self):
          super().__init__()
          self.title = &quot;App&quot;
          self.top = 100
          self.left = 100
          self.width = 680
          self.height = 500
          self.InitUI()
  
      def InitUI(self):
          self.setWindowTitle(self.title)
          self.setGeometry(self.top, self.left, self.width, self.height)
  
          buttonWindow1 = QPushButton('Window1', self)
          buttonWindow1.move(100, 100)
          buttonWindow1.clicked.connect(self.buttonWindow1_onClick)
  
          buttonWindow2 = QPushButton('Window2', self)
          buttonWindow2.move(100, 200)
          buttonWindow2.clicked.connect(self.buttonWindow2_onClick)
  
          self.show()
  
      @pyqtSlot()
      def buttonWindow1_onClick(self):
          self.statusBar().showMessage(&quot;Switched to window 1&quot;)
  
      @pyqtSlot()
      def buttonWindow2_onClick(self):
          self.statusBar().showMessage(&quot;Switched to window 2&quot;)
  
  if __name__ == '__main__':
      app=QApplication(sys.argv)
      ex=Window()
      sys.exit(app.exec_())
  </code></pre>