title: python thread data manipulation
body: <p>I am trying to manipulate some data in a thread from the main function. The issue I am facing about modifying some of the variables which are part of the function which is running on a thread.</p>
  <p>So I am trying to run a Tkinter based GUI loop in a thread to ensure it is always running. And want to modify some of the label corresponding to the status in the main function execution. I am facing an issue where it is unable to locate the label variables in the main loop as it is part of the function running on the thread.</p>
  <p>Below is a simplified psuedo code for that approach. Please suggest if this a correct way to the above task or is there is any better and efficient way.</p>
  <pre class="lang-py prettyprint-override"><code>import threading
  
  def thread_func():
      i = 0
      while True:
          print('i from thread: ', i)
  
  if __name__ == '__main__':
      t = threading.Thread(target=thread_func)
      t.start()
      
      while True:
          i += 1
  </code></pre>
  <p>Actual scaled down simplified code</p>
  <pre class="lang-py prettyprint-override"><code>import threading
  import tkinter as tk
  
  def gui():
      window = tk.Tk()
      label = tk.Label(text='On')
      label.pack()
      window.mainloop()
  
  if __name__ == '__main__':
      t = threading.Thread(target=gui)
      t.start()
      
      while True:
          label['text'] = 'Active'
  </code></pre>
  <p>Error:</p>
  <pre class="lang-sh prettyprint-override"><code>Traceback (most recent call last):
    File &quot;test.py&quot;, line 17, in &lt;module&gt;
      label['text'] = 'Active'
  NameError: name 'label' is not defined
  </code></pre>
  <p>Is there a better way to keep the tkinter gui always on and perform some task in the loop?</p>