I'm currently in the process of developing a modular neural network program that has a Tkinter UI module, a neural network module and a "main" module that allows for the two to communicate.
The issue is that I need to retrieve a list of network parameters (so as to instantiate the neural network class) from a UI class attribute but only once it has been updated (via user interaction with widgets).
A while loop that runs based on whether parameters = []
is not feasible as there is no way, that I'm aware of, to update the window at the same time without multithreading but Tkinter isn't thread-safe.
Apologies for any technical inaccuracies, I am relatively new to programming and its jargon.
UI.py
train = Button(self.parameterframe, text="Train", command=lambda: self.train())
train.place(x=257, y=150)
def train(self):
parameters = [self.epochs.get(), self.layer1neurons.get(),
self.layer2neurons.get(), self.batchsize.get(),
self.learningrate.get()]
for p in parameters:
try:
if p == self.learningrate.get():
float(p)
else:
int(p)
except ValueError:
messagebox.showerror(title="Error", message="Please ensure that all parameters are of the correct type.")
return
self.parameters = parameters
Main.py
def refresh():
root = Tk()
interface = UI.create_ui(root)
while True:
root.update()
time.sleep(0.1)
thread = thread.Thread(target=refresh())
thread.start()
#Then a while loop for retrieving parameters followed by a .join() statement.
Please be aware that the above code is purely experimental and is just to give you an idea of what I'm trying to achieve.