I'm working on a GUI for a math application. Since the calculations often take some time, I'd like to output the interim results to a textfield in a new tkinter window which shall open when the calculation is initiated.

I got to the point where I was able to open a new window and conduct the calculation, but the results are printed after the calculation ends.

I prepared a short code snippet which shows my approach:

```
import tkinter as tk
import threading
import time as t

class CalculationDialog(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.start()
        self.root = tk.Tk()
        self.textField = tk.Text(self.root)
        self.bCloseDialog = tk.Button(self.root, text="Close", state=tk.DISABLED, command=self.root.destroy)
        self.textField.grid(row=1, column=0)
        self.bCloseDialog.grid(row=2, column=0)

    def callback(self):
        self.root.quit()

    def run(self):

        self.root.protocol("WM_DELETE_WINDOW", self.callback)

        self.root.mainloop()

def calculate():
    app = CalculationDialog()

    # Conduct calculation and output to textfield of app

    func(app.textField,0)

def func(output,input):
    for i in range(input,100):
        result = i**2
        output.insert(tk.END,str(result)+"\n")
        t.sleep(0.1)

main = tk.Tk()

buttonCalc = tk.Button(main,text="Calculate",command=calculate)
buttonCalc.pack(side=tk.TOP)

main.mainloop()

```

Does anyone have a suggestion what I am missing?
I sometimes get an error saying that `CalculationDialog` has no attribute `root`.
This error is not always raised however.

Cheers