I am making a GUI and to tidy it up, I'm looking into the possibility of pulling the core functions out into an external script, and having the main GUI call this.
The external module needs to be able to read widget data, and manipulate it.
So for example:
I have a script that has the base of the GUI and when ran, opens it up.
I have another script, inside a folder, which will contain the modules to make the GUI function.
The main GUI script needs to be able to call these modules/functions, and they need to be able to edit the widgets.
I have done some research and none of it is helping, most of the questions are about functions that are in the main script, and I already know how to do this.
Main GUI Script
import os, sys, ttk, pyodbc
from Tkinter import *
import Utils.Common as Common
class GUI:
def __init__(self, *args):
self.style = ttk.Style()
font = "TkDefaultFont"
root.title(uiTitle)
root.iconbitmap(uiIcon)
root.geometry(uiGeometry)
self.connectBtn = ttk.Button(root, width=65)
self.connectBtn.configure(text="Connect", command=Common.connectCleardox)
self.connectBtn.grid(row=0, columnspan=4)
self.exampleEnt = Entry(root, width=30)
self.exampleEnt.grid(row=1, columnspan=4)
if __name__ == '__main__':
root = Tk()
GUI(root)
root.mainloop()
Utils/Common.py
import tkMessageBox
from Tkinter import *
sys.path.insert(0, r'\\cd3\IT\Python\#PythonLibraries\Modules')
from CommonDB import Database
def connectCleardox():
try:
cleardoxConnection = Database.ConnectDatabase(Database(r"\\cd3\IT\Python\#PythonLibraries\ConfigFiles\Cleardox\Cleardox ConfigFile.json"))
exampleEnt.insert(0, 'Success') #The widget from the GUI
except Exception as e:
tkMessageBox.showerror('uiTitle', "Database connection failed.\n\n%s" % (e))
exampleEnt.insert(0, 'Fail') #The widget from the GUI
return
Please let me know if I am being too vague, or not giving enough description.
Thank you all for your time.
Dylan.