title: multiple file download and progress bar update in python
body: <p>I am trying to build one GUI log file downloader tool.</p>
  <p>I am trying to download multiple files at the same time using pyqt5 thread worker.</p>
  <p>I am using callback(supported by paramiko) function to determine the download percentage. I want to update the progress bar(s) for the particular download at the same time. I am not able to figure out how to pass the progressBar details to a call-back function.
  I want to pass &quot;progressBar&quot; to test function(it is a call-back function )</p>
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  import threading
  import time
  from concurrent.futures import ThreadPoolExecutor
  from configurationFileRead import readConfigFile
  import paramiko
  import os
  from functools import partial
  
  
  class FileDownload1(QtCore.QThread):
      percentage = QtCore.pyqtSignal(str, str)
      def __init__(self, fileList, serverList, listProgressBar):
          super().__init__()
          self.fileList = fileList
          self.serverList = serverList
          self.listProgressBar = listProgressBar
      def test(self, size, fileSize):
          sPercentage=((fileSize - size)/fileSize)*100
          if sPercentage != 100:
              sPercentage = 100 - sPercentage
          print(sPercentage)
          
      def _download(self, fileName, serverName, progressBar):
          userId = readConfigFile().getUserId(serverName)
          password = readConfigFile().getPassword(serverName)
          ipAddress = readConfigFile().getIpAddress(serverName)
          logPath = readConfigFile().getLogPath(serverName)
          ssh = paramiko.SSHClient()
          ssh.load_system_host_keys()
          ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
          ssh.connect(ipAddress, username=userId, password=password)
          ftp_client=ssh.open_sftp()
          print(str(os.getcwd()))
          try:
              ftp_client.get(logPath+&quot;/&quot;+fileName,str(os.getcwd())+&quot;/&quot;+fileName, callback = lambda s, t : self.percetage.emit(s, t))
          except Excption as e:
              print(e)
          ftp_client.close()
          ssh.close()
      def run(self):
          j = 0
          with ThreadPoolExecutor(max_workers = 1) as executor:
              while(j &lt; len(self.fileList)):
                  if(self.fileList[j].isChecked()):
                      
                      future= executor.submit(self._download, self.fileList[j].text(), self.serverList[j].text(), self.listProgressBar[j])
                  j = j+1
          print(&quot;Download END&quot;)
  
  
  class logSearch(QtCore.QThread):
      new_signal = QtCore.pyqtSignal(dict)
      def __init__(self, serverList, serachString, archiveFlg, component):
          super().__init__()
          self.serverList = serverList
          self.searchString = serachString
          self.archiveFlg = archiveFlg
          self.component = component
          self.result = {}
      def fileSearch(self, server, searchText):
          try:
  
              userId = readConfigFile().getUserId(server.text())
              password = readConfigFile().getPassword(server.text())
              ipAddress = readConfigFile().getIpAddress(server.text())
              logPath = &quot;&quot;
  
              if(not self.archiveFlg):
                  logPath = readConfigFile().getLogPath(server.text())
              else:
                  logPath = readConfigFile().getLogArchivePath(server.text())
              ssh = paramiko.SSHClient()
              ssh.load_system_host_keys()
              ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
              ssh.connect(ipAddress, username=userId, password=password)
              if(not self.archiveFlg):
                  if self.component == &quot;&quot;:
                      ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(&quot;cd &quot;+logPath+&quot;;for i in *.log\ndo grep -li '&quot;+self.searchString+&quot;' $i\ndone&quot;)
                  else:
                      ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(&quot;cd &quot;+logPath+&quot;;for i in &quot;+self.component+&quot;_*.log\ndo grep -li '&quot;+self.searchString+&quot;' \&quot;$i\&quot;\ndone&quot;)
                      
              else:
                  print(logPath)
                  ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(&quot;cd &quot;+logPath+&quot;;grep -lri '&quot;+self.searchString+&quot;' .&quot;)
              temp1 = ssh_stderr.read()
              print(temp1)
              temp = ssh_stdout.read().decode('utf-8')
              print(temp)
              temp =temp.strip()
              files = list(temp.split(&quot;\n&quot;))
              files = list(filter(None,files))
              i = len(files)
              j=0
              tempDict = {}
              while(j &lt; i):
                  ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(&quot;cd &quot;+logPath+&quot;;ls -l &quot;+files[j])
                  temp = ssh_stdout.read().decode('utf-8')
                  tempLi = list(temp.split(&quot; &quot;))
                  tempLi = list(filter(None,tempLi))
                  fileSize = tempLi[4]
                  tempFileSize  =  int(fileSize)
                  if(tempFileSize &lt; 1024):
  
                      fileSize = str(round(tempFileSize,2)) + &quot; B&quot;
                  else:
                      tempFileSize = tempFileSize/1024
                      if(tempFileSize &lt; 1024):
                          fileSize = str(round(tempFileSize,2)) + &quot; KB&quot;
                      else:
                          tempFileSize = tempFileSize/1024
                          if(tempFileSize &lt; 1024):
                              fileSize = str(round(tempFileSize,2))+ &quot; MB&quot;
                          else:
                              tempFileSize = tempFileSize/1024
                              fileSize = str(round(tempFileSize,2)) + &quot; GB&quot;
  
  
                  fileDate = str(tempLi[5])+&quot; &quot;+str(tempLi[6])+&quot; &quot;+str(tempLi[7])
                  tempLi.clear()
                  tempDict[files[j]] = {'Size':fileSize,'Date':fileDate}
                  j = j+1
              self.result[server.text()]= tempDict
              ssh.close()
  
          except Exception as e:
              print(e)
      def run(self):
          i=len(self.serverList)
          mxW=0
          if(i == 1):
              mxW = 1
          elif(i == 2 or i == 3 or i == 4):
              mxW = 2
          elif(i == 5 or i == 6):
              mxW = 3
          else:
              mxW = 5
          with ThreadPoolExecutor(max_workers = mxW) as executor:
              j=0
              try:
                  while(j &lt; i):
                      future = executor.submit(self.fileSearch, self.serverList[j], self.searchString)
                      j = j+1
              except Exception as e:
                  print(e)
          self.new_signal.emit(self.result)
  
  class Ui_MainWindow(object):
      def _Validate (self):
          validateFlag = True
          if(str(self.searchString.text())== &quot;&quot;):
              self.searchString.setStyleSheet(&quot;border: 2px solid red;&quot;)
              self.searchString.setFocus()
              validateFlag = False
          else:
              self.searchString.setStyleSheet(&quot;border: 1px solid;&quot;)
          if(len(self.serverList.selectedItems())) == 0:
              self.serverList.setStyleSheet(&quot;border: 2px solid red;&quot;)
              validateFlag = False
          elif len(self.serverList.selectedItems()) &gt; 8:
              self.selectedServer.setText(&quot;You can only Choose Upto 8 Server&quot;)
              self.selectedServer.setStyleSheet(&quot;color:blue;font:Bold&quot;)
              self.serverList.setStyleSheet(&quot;border: 2px solid red;&quot;)
              validateFlag = False
          elif len(self.serverList.selectedItems()) &gt; 1 and self.specificFileFlag.isChecked() == True:
              self.selectedServer.setText(&quot;Select only one Server&quot;)
              self.selectedServer.setStyleSheet(&quot;color:red;font:Bold&quot;)
              validateFlag = False
          else:
              self.serverList.setStyleSheet(&quot;border: 1px solid;&quot;)
          if(validateFlag):
              self.downloadSelected.setDisabled(True)
              i=len(self.listProgressBar)
              n=0
              while(i &gt; 0):
                  self.listProgressBar[n].deleteLater()
                  self.listCheckBox[n].deleteLater()
                  self.listDateLabel[n].deleteLater()
                  self.listSizeLabel[n].deleteLater()
                  self.listServerLabel[n].deleteLater()
                  i = i-1;
                  n=n+1
              self.listProgressBar.clear()
              self.listCheckBox.clear()
              self.listDateLabel.clear()
              self.listSizeLabel.clear()
              self.listServerLabel.clear()
              self.submit.setDisabled(True)
              self.errorLabel.setText(&quot;Search Started...&quot;)
              self.logSearch = logSearch(self.serverList.selectedItems(), self.searchString.text(), self.searchArchive.isChecked(), self.comonentComboBox.currentText())
              self.logSearch.new_signal.connect(self.printResult)
              self.logSearch.start()
      def printResult(self, result):
          self.errorLabel.setText(&quot;Search Completed&quot;)
          serverList = list(result.keys())
          print(result)
          l = len(serverList)
          k=0
          m = 0
          i = 0
          while(i &lt; l):
              logNameList = list(result[serverList[i]].keys())
              n= len(logNameList)
              j=0
              while(j &lt; n):
                  self.listCheckBox.append(QtWidgets.QCheckBox())
                  self.listSizeLabel.append(QtWidgets.QLabel(result[serverList[i]][logNameList[j]]['Size']))
                  self.listDateLabel.append(QtWidgets.QLabel(result[serverList[i]][logNameList[j]]['Date']))
                  self.listCheckBox[m].setText(logNameList[j])
                  self.gridLayout_2.addWidget(self.listCheckBox[m], m, 0)
                  self.listServerLabel.append(QtWidgets.QLabel())
                  self.listServerLabel[m].setText(serverList[i])
                  self.gridLayout_2.addWidget(self.listServerLabel[m], m, 1)
                  self.gridLayout_2.addWidget(self.listSizeLabel[m], m, 2)
                  self.gridLayout_2.addWidget(self.listDateLabel[m], m, 3)
                  self.listProgressBar.append(QtWidgets.QProgressBar())
                  self.listProgressBar[m].setValue(0)
                  self.gridLayout_2.addWidget(self.listProgressBar[m], m, 4)
                  j = j+1
                  m=m+1
              i = i+1
          self.submit.setDisabled(False)
          self.downloadSelected.setDisabled(False)
      def hello122(self):
          print(&quot;invoked&quot;)
      def _FileDownload(self):
          self.test = FileDownload1(self.listCheckBox, self.listServerLabel, self.listProgressBar)
          self.test.percentage.connect(self.hello122)
          self.test.start()
      def _ArchiveFlag(self):
          if (self.searchArchive.isChecked()):
              self.autoDownload.setChecked(True)
              self.autoDownload.setDisabled(True)
          else:
              self.autoDownload.setDisabled(False)
      def _FileDownloadFlag(self):
          if(self.specificFileFlag.isChecked()):
              self.label.setText(&quot;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=\&quot; font-weight:600; color:#000000;\&quot;&gt;File Name&lt;/span&gt;&lt;span style=\&quot; font-weight:600; color:#ff0000;\&quot;&gt;*&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;)
              self.submit.setText(&quot;Download File&quot;)
              self.autoDownload.setChecked(False)
              self.autoDownload.setDisabled(True)
              self.searchArchive.setDisabled(True)
              self.comonentComboBox.hide()
              self.downloadSelected.setDisabled(True)
          else:
               self.label.setText(&quot;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=\&quot; font-weight:600; color:#000000;\&quot;&gt;Search String&lt;/span&gt;&lt;span style=\&quot; font-weight:600; color:#ff0000;\&quot;&gt;*&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;)
               self.submit.setText(&quot;Search&quot;)
               self.comonentComboBox.show()
               self.autoDownload.setDisabled(False)
               self.searchArchive.setDisabled(False)
      def _serverList(self):
              if len(self.serverList.selectedItems()) &gt; 8 :
                  self.selectedServer.setText(&quot;You can only Choose Upto 8 Server&quot;)
                  self.selectedServer.setStyleSheet(&quot;color:red;font:Bold&quot;)
              elif len(self.serverList.selectedItems()) &gt; 1 and self.specificFileFlag.isChecked() == True:
                  self.selectedServer.setText(&quot;Select only one Server&quot;)
                  self.selectedServer.setStyleSheet(&quot;color:red;font:Bold&quot;)
              elif len(self.serverList.selectedItems()) == 0:
                  self.selectedServer.setText(&quot;&quot;)
              else:
                  self.selectedServer.setText(str([item.text() for item in self.serverList.selectedItems()]))
                  self.selectedServer.setStyleSheet(&quot;color:black;font:regular&quot;)
                  self.serverList.setStyleSheet(&quot;border: 1px solid;&quot;)
  
  
      def setupUi(self,MainWindow):
          MainWindow.setObjectName(&quot;MainWindow&quot;)
          MainWindow.resize(823, 588)
          sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
          sizePolicy.setHorizontalStretch(0)
          sizePolicy.setVerticalStretch(0)
          sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
          MainWindow.setSizePolicy(sizePolicy)
          self.centralwidget = QtWidgets.QWidget(MainWindow)
          self.centralwidget.setObjectName(&quot;centralwidget&quot;)
          self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
          self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 40, 761, 60))
          self.verticalLayoutWidget.setObjectName(&quot;verticalLayoutWidget&quot;)
          self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
          self.verticalLayout.setContentsMargins(0, 0, 0, 0)
          self.verticalLayout.setObjectName(&quot;verticalLayout&quot;)
          self.gridLayout = QtWidgets.QGridLayout()
          self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
          self.gridLayout.setObjectName(&quot;gridLayout&quot;)
          self.label = QtWidgets.QLabel(self.verticalLayoutWidget)
          self.label.setObjectName(&quot;label&quot;)
          self.gridLayout.addWidget(self.label, 0, 0, 1, 1, QtCore.Qt.AlignLeft)
          self.searchString = QtWidgets.QLineEdit(self.verticalLayoutWidget)
          self.searchString.setMaximumSize(QtCore.QSize(673, 16777215))
          self.searchString.setObjectName(&quot;searchString&quot;)
          self.gridLayout.addWidget(self.searchString, 0, 1, 1, 1)
          self.submit = QtWidgets.QPushButton(self.verticalLayoutWidget)
          self.submit.setObjectName(&quot;submit&quot;)
          self.gridLayout.addWidget(self.submit, 0, 4, 1, 1)
          self.componentLabel = QtWidgets.QLabel(self.verticalLayoutWidget)
          self.componentLabel.setObjectName(&quot;componentLabel&quot;)
          self.gridLayout.addWidget(self.componentLabel, 0, 2, 1, 1)
          self.comonentComboBox = QtWidgets.QComboBox(self.verticalLayoutWidget)
          self.comonentComboBox.setObjectName(&quot;comonentComboBox&quot;)
          self.comonentComboBox.addItem(&quot;&quot;)
          lengthOfComponent = len(readConfigFile().getComponentList())
          m=0
          while(m &lt; lengthOfComponent):
              self.comonentComboBox.addItem(readConfigFile().getComponentList()[m])
              m = m+1
          self.gridLayout.addWidget(self.comonentComboBox, 0, 3, 1, 1)
          self.verticalLayout.addLayout(self.gridLayout)
          self.errorLabel = QtWidgets.QLabel(self.centralwidget)
          self.errorLabel.setGeometry(QtCore.QRect(30, 10, 751, 16))
          self.errorLabel.setText(&quot;&quot;)
          self.errorLabel.setObjectName(&quot;errorLabel&quot;)
          self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
          self.groupBox.setGeometry(QtCore.QRect(40, 140, 361, 151))
          self.groupBox.setObjectName(&quot;groupBox&quot;)
          self.serverList = QtWidgets.QListWidget(self.groupBox)
          self.serverList.setEnabled(True)
          self.serverList.setGeometry(QtCore.QRect(10, 20, 331, 121))
          self.serverList.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
          self.serverList.setResizeMode(QtWidgets.QListView.Fixed)
          self.serverList.setObjectName(&quot;serverList&quot;)
          item = QtWidgets.QListWidgetItem()
          lengthOfServers = len(readConfigFile().getServerList())
          k=0
          while( k &lt; lengthOfServers):
              if readConfigFile().getServerList()[k] != &quot;Component&quot;:
                  self.serverList.addItem(readConfigFile().getServerList()[k])
              k = k+1
          self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
          self.groupBox_2.setGeometry(QtCore.QRect(410, 140, 361, 151))
          self.groupBox_2.setObjectName(&quot;groupBox_2&quot;)
          self.autoDownload = QtWidgets.QCheckBox(self.groupBox_2)
          self.autoDownload.setGeometry(QtCore.QRect(10, 30, 121, 20))
          self.autoDownload.setObjectName(&quot;autoDownload&quot;)
          self.specificFileFlag = QtWidgets.QCheckBox(self.groupBox_2)
          self.specificFileFlag.setGeometry(QtCore.QRect(10, 60, 171, 20))
          self.specificFileFlag.setObjectName(&quot;specificFileFlag&quot;)
          self.downloadSelected = QtWidgets.QPushButton(self.groupBox_2)
          self.downloadSelected.setGeometry(QtCore.QRect(10, 97, 141, 31))
          self.downloadSelected.setObjectName(&quot;downloadSelected&quot;)
          self.searchArchive = QtWidgets.QCheckBox(self.groupBox_2)
          self.searchArchive.setGeometry(QtCore.QRect(170, 30, 141, 20))
          self.searchArchive.setObjectName(&quot;searchArchive&quot;)
          self.checkBox = QtWidgets.QCheckBox(self.groupBox_2)
          self.checkBox.setGeometry(QtCore.QRect(170, 60, 191, 21))
          self.checkBox.setObjectName(&quot;checkBox&quot;)
          self.label_2 = QtWidgets.QLabel(self.centralwidget)
          self.label_2.setGeometry(QtCore.QRect(640, 540, 161, 20))
          self.label_2.setObjectName(&quot;label_2&quot;)
          self.selectedServer = QtWidgets.QLabel(self.centralwidget)
          self.selectedServer.setGeometry(QtCore.QRect(30, 110, 751, 21))
          self.selectedServer.setText(&quot;&quot;)
          self.selectedServer.setObjectName(&quot;selectedServer&quot;)
          self.serverList.itemSelectionChanged.connect(self._serverList)
          self.submit.clicked.connect(self._Validate)
          self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
          self.horizontalLayoutWidget.setGeometry(QtCore.QRect(40, 310, 731, 211))
          self.horizontalLayoutWidget.setObjectName(&quot;horizontalLayoutWidget&quot;)
          self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
          self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
          self.horizontalLayout.setObjectName(&quot;horizontalLayout&quot;)
          self.scrollArea = QtWidgets.QScrollArea(self.horizontalLayoutWidget)
          self.scrollArea.setWidgetResizable(True)
          self.scrollArea.setObjectName(&quot;scrollArea&quot;)
          self.scrollAreaWidgetContents = QtWidgets.QWidget()
          self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 727, 207))
          self.scrollAreaWidgetContents.setObjectName(&quot;scrollAreaWidgetContents&quot;)
          self.gridLayout_2 = QtWidgets.QGridLayout(self.scrollAreaWidgetContents)
          self.gridLayout_2.setContentsMargins(10, 10, 10, 10)
          self.gridLayout_2.setObjectName(&quot;gridLayout_2&quot;)
          self.scrollArea.setWidget(self.scrollAreaWidgetContents)
          self.horizontalLayout.addWidget(self.scrollArea)
          MainWindow.setCentralWidget(self.centralwidget)
          self.statusbar = QtWidgets.QStatusBar(MainWindow)
          self.statusbar.setObjectName(&quot;statusbar&quot;)
          MainWindow.setStatusBar(self.statusbar)
          self.listCheckBox = []
          self.listProgressBar = []
          self.listServerLabel = []
          self.listSizeLabel = []
          self.listDateLabel = []
          self.searchArchive.toggled.connect(self._ArchiveFlag)
          self.specificFileFlag.toggled.connect(self._FileDownloadFlag)
          self.downloadSelected.clicked.connect(self._FileDownload)
          self.downloadSelected.setDisabled(True)
          self.checkBox.setDisabled(True)
          self.retranslateUi(MainWindow)
          QtCore.QMetaObject.connectSlotsByName(MainWindow)
  
      def retranslateUi(self, MainWindow):
          _translate = QtCore.QCoreApplication.translate
          MainWindow.setWindowTitle(_translate(&quot;MainWindow&quot;, &quot;MainWindow&quot;))
          self.label.setText(_translate(&quot;MainWindow&quot;, &quot;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=\&quot; font-weight:600; color:#000000;\&quot;&gt;Search String&lt;/span&gt;&lt;span style=\&quot; font-weight:600; color:#ff0000;\&quot;&gt;*&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;))
          self.submit.setText(_translate(&quot;MainWindow&quot;, &quot;Search&quot;))
          self.groupBox.setTitle(_translate(&quot;MainWindow&quot;, &quot;Server List&quot;))
          __sortingEnabled = self.serverList.isSortingEnabled()
          self.serverList.setSortingEnabled(False)
          self.serverList.setSortingEnabled(__sortingEnabled)
          self.groupBox_2.setTitle(_translate(&quot;MainWindow&quot;, &quot;Other Configuration&quot;))
          self.autoDownload.setToolTip(_translate(&quot;MainWindow&quot;, &quot;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;))
          self.autoDownload.setText(_translate(&quot;MainWindow&quot;, &quot;Auto Download&quot;))
          self.specificFileFlag.setToolTip(_translate(&quot;MainWindow&quot;, &quot;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;write the file name in &amp;quot;Search String&amp;quot; and Click on Search Button&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;))
          self.specificFileFlag.setText(_translate(&quot;MainWindow&quot;, &quot;Download Specific file&quot;))
          self.downloadSelected.setText(_translate(&quot;MainWindow&quot;, &quot;Download Selected&quot;))
          self.searchArchive.setText(_translate(&quot;MainWindow&quot;, &quot;Search in Archive&quot;))
          self.checkBox.setToolTip(_translate(&quot;MainWindow&quot;, &quot;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This option will try to compress the file in server before downloading&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;))
          self.checkBox.setText(_translate(&quot;MainWindow&quot;, &quot;Compress Before Download&quot;))
          self.label_2.setText(_translate(&quot;MainWindow&quot;, &quot;&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=\&quot; color:#969696;\&quot;&gt;Created by - Sudipto Khan&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;))
  
  
  if __name__ == &quot;__main__&quot;:
      import sys
      app = QtWidgets.QApplication(sys.argv)
      MainWindow = QtWidgets.QMainWindow()
      ui = Ui_MainWindow()
      ui.setupUi(MainWindow)
      MainWindow.show()
      sys.exit(app.exec_())
  
  </code></pre>