title: PyQt5 dynamic add QFormLayouts into tabs of QTabWidget
body: <p>I am a complete noob to Python and PyQT5. And my first post to stackoverflow. Forgive any lack of protocol that i may have. I am creating a program that reads an excel file.  This XL file will have multiple sheets. The program first creates a mainwindow where it collects some information. After the user pushes a button, the program then opens a new window with a QTabWidget.</p>
  
  <p><img src="https://i.stack.imgur.com/BdnbQ.png" alt=""></p>
  
  <p>This QTabWidget is being dynamically created so that the tab names are set by a list of XL sheet names. In each tab I want to put in a QFormLayout of labels and comboboxes.  The qformlayout will be the same for each tab but i want to dynamically set the selections for each combobox on each tab.</p>
  
  <p>This is my code:</p>
  
  <pre><code>class TabWindow(QWidget):
  
       def __init__(self):
          super().__init__()
          self.title = 'Tape Column Mapping'
          self.left = 100
          self.top = 100
          self.width = 640
          self.height = 570
          self.initUI()
  
      def initUI(self):
          self.setWindowTitle(self.title)
          self.setGeometry(self.left, self.top, self.width, self.height)
  
          self.lbl = QLabel('For each worksheet you want to analyze, please associate each field with the appropriate worksheet column:',self)
          self.lbl.setGeometry(10,10,621,31)
          self.lbl.setFont(QFont("MS Shell Dlg 2", 8, QFont.Bold))
  
      def initFormLayout(self):
          self.formLayout = QFormLayout(self)
          self.formLayout.addRow(QLabel("Address"),QComboBox())
          self.formLayout.addRow(QLabel("City"),QComboBox())
          self.formLayout.addRow(QLabel("State"),QComboBox())
          self.formLayout.addRow(QLabel("Zip"),QComboBox())
          self.formLayout.addRow(QLabel("UPB"),QComboBox())
          self.formLayout.addRow(QLabel("Interest Rate"),QComboBox())
          self.formLayout.addRow(QLabel("P&amp;I"),QComboBox())
          self.formLayout.addRow(QLabel("Term"),QComboBox())
          self.formLayout.addRow(QLabel("Original Balance"),QComboBox())
          self.formLayout.addRow(QLabel("Note Date"),QComboBox())
          self.formLayout.addRow(QLabel("Last Paid To"),QComboBox())
          self.formLayout.addRow(QLabel("Next Due Date"),QComboBox())
          self.formLayout.addRow(QLabel("Maturity Date"),QComboBox())
          self.formLayout.addRow(QLabel("Asset Type"),QComboBox())
          self.formLayout.addRow(QLabel("Note Status"),QComboBox())
          self.setLayout(formLayout)
  
  class MainWindow(QWidget):
  
      def __init__(self):
          super().__init__()
          self.title = 'NPN Tape Analyzer'
          self.left = 100
          self.top = 100
          self.width = 640
          self.height = 480
          self.initUI()
  
      def initUI(self):
          self.setWindowTitle(self.title)
          self.setGeometry(self.left, self.top, self.width, self.height)
  
          self.lbl = QLabel('NPN Tape Analyzer',self)
          self.lbl.setGeometry(20,10,231,31)
          self.lbl.setFont(QFont("MS Shell Dlg 2", 16, QFont.Bold))
  
  
          self.lbl1 = QLabel('(Open Tape Excel File)',self)
          self.lbl1.setGeometry(250,100,140,20)
          self.lbl1.setFont(QFont("MS Shell Dlg 2", 8))
          self.lbl1.setAlignment(Qt.AlignCenter)
  
  
          self.lbl2 = QLabel('Select Worksheets to analyze (ctrl + click for multiple selections):',self)
          self.lbl2.setGeometry(50,190,420,20)
          self.lbl2.setFont(QFont("MS Shell Dlg 2", 9, QFont.Bold))
  
  
          btn = QPushButton('START ANALYSIS',self)
          btn.setGeometry(260,60,121,41)
          btn.setFont(QFont("Arial", 8, QFont.Bold))
          btn.clicked.connect(self.openXLworksheetDialog)
  
          btn1 = QPushButton('NEXT &gt;&gt;',self)
          btn1.setGeometry(500,280,75,23)
          btn1.setFont(QFont("Arial", 8))
          btn1.clicked.connect(self.collectSelectedSheets)
  
          btn2 = QPushButton('Exit Application',self)
          btn2.setGeometry(210,380,220,40)
          btn2.setFont(QFont("Arial", 10, QFont.Bold))
          btn2.clicked.connect(self.close)
  
          self.fnametextBox = QLineEdit(self)
          self.fnametextBox.setGeometry(35,150,571,20)
          self.fnametextBox.setText("&lt;No File&gt;")
          self.fnametextBox.setAlignment(Qt.AlignCenter)
          self.fnametextBox.setStyleSheet("color: rgb(128, 128, 128);")
          self.fnametextBox.setReadOnly(True)
  
          self.sheetListWidg = QListWidget(self)
          self.sheetListWidg.setGeometry(200,220,241,151)
          self.sheetListWidg.setStyleSheet("color: rgb(0, 0, 255);")
          self.sheetListWidg.setSelectionMode(QAbstractItemView.ExtendedSelection)
  
      def openXLworksheetDialog(self):              
          options = QFileDialog.Options()
          options |= QFileDialog.DontUseNativeDialog
          XLfilename, _ = QFileDialog.getOpenFileName(self,"Open MS Excel file","","Newer Excel files (*.xlsx);;Older Excel files (*.xls)",options=options)
          if XLfilename:
              self.fnametextBox.setText(XLfilename)
              self.WBdict = pd.read_excel(XLfilename, sheet_name=None)
              for key in self.WBdict:
                  self.sheetListWidg.addItem(key)
  
      def collectSelectedSheets(self):
          tmpselSheets = self.sheetListWidg.selectedItems()
          self.selSheetList = []
          for i in range(len(tmpselSheets)):
              self.selSheetList.append(str(self.sheetListWidg.selectedItems()[i].text()))
          print(self.selSheetList)
  
  
      def closeEvent(self, event):
              """Generate 'question' dialog on clicking 'X' button in title bar.
  
              Reimplement the closeEvent() event handler to include a 'Question'
              dialog with options on how to proceed - Close or Cancel buttons
              """
              reply = QMessageBox.question(
                  self, "Message",
                  "You are exiting the application. Are you sure you want to quit?",
                  QMessageBox.Close | QMessageBox.Cancel,
                  QMessageBox.Close)
  
              if reply == QMessageBox.Close:
                  event.accept()
              else:
                  event.ignore()
  
  
  if __name__ == '__main__':
  
      app = QApplication(sys.argv)
      mainwindow = MainWindow()
      mainwindow.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>But I do not think the TabWindow class portion is correct, particularly the use of 'self'. I have not tried to instantiate the TabWindow part yet. But the MainWindow part works so far. Here are my questions:</p>
  
  <p>1) If this is a 2nd window, am i supposed to use self in the 2nd window class?</p>
  
  <p>2) How would I go about accessing the QComboBoxes in the TabWidget after they are created? A list of some sort?</p>