I'm writing a script and I'd like to use Tkinter GUI (or any other module which could do this) to show how many times in total this script has been run, store the number in file and update GUI dynamically from this file. But each time I call label.mainloop() nothing past this line gets executed, it just freezes there.
import tkinter
import time
def tracker():
f = open('howmanytimes.txt', 'r')
thenumber = f.read()
f.close()
tracker = 'Script has run this many times: ' + (str(thenumber))
label = tkinter.Label(text=tracker, font=(
'Times', '20'), fg='red', bg='black')
label.master.overrideredirect(True)
label.master.geometry("+0+0")
label.pack()
label.master.wm_attributes("-topmost", True)
label.mainloop()
tracker() # <- Nothing past this line gets executed
time.sleep(2)
i = 0
while i < 20:
print('Script has been run')
time.sleep(3)
f = open('howmanytimes.txt', 'w+')
thenumber = f.read()
g = int(thenumber) + 1
f.write(str(g))
f.close()
tracker()
i+=1