I've got a working code for the training of a neural network. Now I want to create a TkInter GUI to be able to e.g. change the parameters on the fly. I imagine it being like a remote control. But I am struggling to get a responsive interface. The training of one epoch will take a couple of minutes without me being able to intercept.
I've seen a lot of examples which use the .after() method to maybe update a clock on the GUI, which is fine, because updating doesn't take minutes. I can't get it to work, when the callback takes minutes.
I recreated my problem with the minimal amount of code:
from time import sleep
import tkinter as tk
def trainEpoch(i):
print ("Training", i)
sleep(1) #in reality more like sleep(300)
def clickBtn():
print ("Button pressed")
root = tk.Tk()
btn = tk.Button(root, text="Click Me", command=clickBtn)
btn.grid(column=0, row=0)
for i in range (5):
trainEpoch(i)
print ("finished" )
root.mainloop()
This code first "trains" the network, then creates a responsive TkInter window (which I fully understand).
Just to be clear, I wish the following behaviour:
I want the GUI to open before the training starts and be clickable while the training is doing its thing. I don't care if it gets destroyed afterwards.
Do I need threading for this kind of problem?