title: Multiple windows in pyqt5
body: <p>This algorithm allows a new window to be opened each time a button is clicked, but when it is clicked again the window closes, I need to modify it in such a way that clicking it generates a new window each time without being close the previous one.</p>
  <p>Code:</p>
  <pre><code>import sys
  from random import randint
  
  from PyQt5.QtWidgets import (
      QApplication,
      QLabel,
      QMainWindow,
      QPushButton,
      QVBoxLayout,
      QWidget,
  )
  
  
  class AnotherWindow(QWidget):
      &quot;&quot;&quot;
      This &quot;window&quot; is a QWidget. If it has no parent,
      it will appear as a free-floating window.
      &quot;&quot;&quot;
  
      def __init__(self):
          super().__init__()
          layout = QVBoxLayout()
          self.label = QLabel(&quot;Another Window % d&quot; % randint(0, 100))
          layout.addWidget(self.label)
          self.setLayout(layout)
  
  
  class MainWindow(QMainWindow):
      def __init__(self):
          super().__init__()
          self.window1 = AnotherWindow()
          self.window2 = AnotherWindow()
  
          l = QVBoxLayout()
          button1 = QPushButton(&quot;Push for Window 1&quot;)
          button1.clicked.connect(self.toggle_window1)
          l.addWidget(button1)
  
          button2 = QPushButton(&quot;Push for Window 2&quot;)
          button2.clicked.connect(self.toggle_window2)
          l.addWidget(button2)
  
          w = QWidget()
          w.setLayout(l)
          self.setCentralWidget(w)
  
      def toggle_window1(self, checked):
          if self.window1.isVisible():
              self.window1.hide()
  
          else:
              self.window1.show()
  
      def toggle_window2(self, checked):
          if self.window2.isVisible():
              self.window2.hide()
  
          else:
              self.window2.show()
  
  
  app = QApplication(sys.argv)
  w = MainWindow()
  w.show()
  app.exec_()
  </code></pre>
  <p>I have tried changing the windows variable for a new widget each time the button is given but it doesn't work</p>