code: def close_client(self, index=None, client=None, save=False):
          
          if not self.tabwidget.count():
              return
          if client is not None:
              index = self.tabwidget.indexOf(client)
          if index is None and client is None:
              index = self.tabwidget.currentIndex()
          if index is not None:
              client = self.tabwidget.widget(index)
  
          is_welcome = client.get_filename() == WELCOME
          if not save and not is_welcome:
              client.save()
              wait_save = QEventLoop()
              QTimer.singleShot(1000, wait_save.quit)
              wait_save.exec_()
              path = client.get_filename()
              fname = osp.basename(path)
              nb_contents = nbformat.read(path, as_version=4)
  
              if ('untitled' in fname and len(nb_contents['cells']) > 0 and
                      len(nb_contents['cells'][0]['source']) > 0):
                  buttons = QMessageBox.Yes | QMessageBox.No
                  answer = QMessageBox.question(self, self.get_plugin_title(),
                                                _("<b>{0}</b> has been modified."
                                                  "<br>Do you want to "
                                                  "save changes?".format(fname)),
                                                buttons)
                  if answer == QMessageBox.Yes:
                      self.save_as(close=True)
          if not is_welcome:
              client.shutdown_kernel()
          client.close()
  
          # Delete notebook file if it is in temporary directory
          filename = client.get_filename()
          if filename.startswith(get_temp_dir()):
              try:
                  os.remove(filename)
              except EnvironmentError:
                  pass
  
          # Note: notebook index may have changed after closing related widgets
          self.tabwidget.removeTab(self.tabwidget.indexOf(client))
          self.clients.remove(client)
  
          self.create_welcome_client()
docs: Close client tab from index or widget (or close current tab).