title: How do I add a PyQt menubar to my program?
body: <p>I'm currently working on a user interface for my Python program with PyQt5.</p>
  
  <p>In my program I first read a csv file and then create a dataframe with pandas. This also works so far.</p>
  
  <p>Now I want to create a user interface with PyQt5. This interface should contain a menubar with two buttons ("File" and "Run") and should display my dataframe <strong>(see picture)</strong>. </p>
  
  <p>How it finally should look like</p>
  
  <p><img src="https://i.stack.imgur.com/JBj6X.jpg" alt=""></p>
  
  <p>With the first button I want to read my csv file and with the other I want to start the program. </p>
  
  <p>Currently I can only display a dataframe with my user interface <strong>(see picture)</strong>.</p>
  
  <p>How it looks right now</p>
  
  <p><img src="https://i.stack.imgur.com/yLU4Z.jpg" alt=""></p>
  
  <p><strong>That is my code at the moment with a random dataframe</strong></p>
  
  <pre><code>import sys
  import pandas as pd
  from PyQt5.QtWidgets import QApplication, QTableView
  from PyQt5.QtCore import QAbstractTableModel, Qt
  
  df = pd.DataFrame({'A': ['AAAAAAAA11111111', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz'],
                     'B': ['BBBBBBBB11111111', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz'],
                     'C': ['CCCCCCCC11111111', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz'],        
                     'D': ['CCCCCCCC11111111', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz', 'xyz']})
  
  class pandasModel(QAbstractTableModel):
  
      def __init__(self, data):
          QAbstractTableModel.__init__(self)
          self._data = data
  
      def rowCount(self, parent=None):
          return self._data.shape[0]
  
      def columnCount(self, parent=None):
          return self._data.shape[1]
  
      def data(self, index, role=Qt.DisplayRole):
          if index.isValid():
              if role == Qt.DisplayRole:
                  return str(self._data.iloc[index.row(), index.column()])
          return None
  
      def headerData(self, col, orientation, role):
          if orientation == Qt.Horizontal and role == Qt.DisplayRole:
              return self._data.columns[col]
          return None
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
      model = pandasModel(df)
      view = QTableView()
      view.setModel(model)
      view.resize(800, 300)
      view.horizontalHeader().setSectionResizeMode(1) 
      view.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>In order to maintain my desired user interface, I have created a PyQt Designer interface with a menu bar (see picture). But I have no idea how to link these two interfaces. </p>
  
  <p>Design from PyQt_Designer</p>
  
  <p><img src="https://i.stack.imgur.com/cZlAJ.jpg" alt=""></p>
  
  <p><strong>Code from PyQt Designer:</strong></p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  
  
  class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
  
          MainWindow.setObjectName("MainWindow")
          MainWindow.resize(600, 300)
          icon = QtGui.QIcon()
          icon.addPixmap(QtGui.QPixmap("../../Desktop/index.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  
          MainWindow.setWindowIcon(icon)
          self.centralwidget = QtWidgets.QWidget(MainWindow)
          self.centralwidget.setObjectName("centralwidget")
          self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
          self.tableWidget.setGeometry(QtCore.QRect(0, 0, 600, 300))
          self.tableWidget.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.CrossCursor))
          self.tableWidget.setObjectName("tableWidget")
          self.tableWidget.setColumnCount(0)
          self.tableWidget.setRowCount(0)
  
          MainWindow.setCentralWidget(self.centralwidget)
          self.menubar = QtWidgets.QMenuBar(MainWindow)
          self.menubar.setGeometry(QtCore.QRect(0, 0, 600, 21))
          self.menubar.setObjectName("menubar")
          self.menuSelect = QtWidgets.QMenu(self.menubar)
          self.menuSelect.setObjectName("menuSelect")
  
          MainWindow.setMenuBar(self.menubar)
          self.statusbar = QtWidgets.QStatusBar(MainWindow)
          self.statusbar.setObjectName("statusbar")
          MainWindow.setStatusBar(self.statusbar)
          self.menubar.addAction(self.menuSelect.menuAction())
  
          self.retranslateUi(MainWindow)
          QtCore.QMetaObject.connectSlotsByName(MainWindow)
  
      def retranslateUi(self, MainWindow):
          _translate = QtCore.QCoreApplication.translate
          MainWindow.setWindowTitle(_translate("MainWindow", "Analyser"))
          self.menuSelect.setTitle(_translate("MainWindow", "Select File"))
  
  
  if __name__ == "__main__":
      import sys
      app = QtWidgets.QApplication(sys.argv)
      MainWindow = QtWidgets.QMainWindow()
      ui = Ui_MainWindow()
      ui.setupUi(MainWindow)
      MainWindow.show()
      sys.exit(app.exec_())
  
  </code></pre>
  
  <p>How can I add a menubar to my program or alternatively how to link my program to the code of the PyQt Designer? </p>