Updated to fix the issue where I'm opening the connection on import but closing at the end of each function. added a database manager class and added the OnExit in the UI mainloop to close the db connection.