title: Python referencing database connection on another script
body: <p>I'm in the depths of learning Python whilst trying to make an application, using data stored on a MySQL/MariaDB, and I am nearly at the stage that I can make some good progress with the project. I can connect to my DB via SSH, and retrieve data from a python script, but I am now looking to display that data in a GUI box. One of the challenges I'm facing is that I have two separate scripts to handle the connections, one to open and one to close, my theory being that a connection is only needed for data access. I've used PyQT5 to create the various GUIs and windows, and specifically I am looking to populate a QtTableWidget. The script I have doesn't currently give me any errors, but neither does it display the data in the table widget. My hunch is that it's not correctly referencing the database on the open connection script, and therefore has no data to pass, but I am struggling to identify the terminology needed for an effective google search. </p>
  
  <p>My OpenConn.py is as follows:</p>
  
  <pre><code>import MySQLdb
  from sshtunnel import SSHTunnelForwarder
  
  def Open_Conn():
      with SSHTunnelForwarder(
               ('192.168.0.10', 22),
               ssh_password="xxx",
               ssh_username="xxx",
               remote_bind_address=('localhost', 3306)) as server:
  
          db = MySQLdb.connect(host='localhost',
                                 port=server.local_bind_port,
                                 user='xxx',
                                 passwd='xxx',
                                 db='DBNAME')
  
          cursor = db.cursor()
  if __name__ == '__main__':
      Open_Conn()
  </code></pre>
  
  <p>And my main.py is as follows:</p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  import sys
  from ViewClientsUI import Ui_ViewClients
  from OpenConn import Open_Conn
  
  class ViewClientsWindow(QtWidgets.QDialog, Ui_ViewClients):
      def __init__(self):
          super(ViewClientsWindow, self).__init__()
          self._new_window = None
          self.setupUi(self)
  
      def data_load():
          with OpenConn.Open_Conn:
              connection = OpenConn.Open_Conn()
              query = "SELECT * FROM Clients"
              result = connection.execute(query)
              self.tableWidget.setRowCount(0)
              for row_number, row_data in enumerate(result):
                  self.tableWidget.insertRow(row_number)
                  for column_number, data in enumerate(row_data):
                      self.tableWidget.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
  
  if __name__ == '__main__':
      app = QtWidgets.QApplication(sys.argv)
      gui = ViewClientsWindow()
      gui.show()
      app.exec_()
      Open_Conn()
  </code></pre>
  
  <p>Can anyone help my identify why I'm not getting data in the table widget?
  Many thanks in advance</p>