title: How to update variables from a text file in a GUI in real time? Python and tkinter
body: <p>I have a script that continuously updates numbers on a text file in the same directory. I made a GUI using tkinter to display these numbers. I'm having a hard time getting the GUI to update the numbers in real time. It will display the numbers as they were when the GUI first started, but will not update the display as the text file changes. Here's some basic code to demonstrate:</p>
  <pre><code>def read_files(file, line):
      old = open(f'{file}.txt', 'r').readlines()[line]
      new = old.replace('\n', '')
      return new
  
  number = read_files('Statistics', 0)
  number_label = Label(frame1, text=f'{number}')
  number_label.grid(row=0, column=0)
  </code></pre>
  <p>The above code shows the number from the text file as it was when the GUI first opened. However, it does not update the number as its value in the text file changes. I did some reading around and also tried the following:</p>
  <pre><code>def read_files(file, line):
      old = open(f'{file}.txt', 'r').readlines()[line]
      new = old.replace('\n', '')
      return new
  
  number = read_files('Statistics', 0)
  number_label = StringVar()
  number_label.set(number)
  number_display = Label(frame1, text=f'{number_label.get()}')
  number_display.grid(row=0, column=0)
  </code></pre>
  <p>This has the same effect. It shows the value retrieved from the text file at the moment the GUI was opened, but does not update it as the text file is updated. Any help is appreciated.</p>