title: How to make tkinter button interact with my script?
body: <p>I am new to coding and trying to figure this out and I cannot, and I can't seem to find any videos on youtube that shows this either. </p>
  
  <p>Essentially what i want to do is have a loop running, and be able to click a button and it change a variable in the loop.  For instance:</p>
  
  <pre><code>from tkinter import *
  import time
  
  root = Tk()
  x = 0
  
  def changeVariable():
      x = x + 5
  
  button1 = Button(root, text="add 5", command=changeVariable)
  button1.pack()
  
  while True:
      root.mainloop()
      while x &gt; 0:
          print("X is greater than 0")
          x = x - 1
          time.sleep(1)
      else:
          print("Please click the button")
          time.sleep(1)
  </code></pre>
  
  <p>I have tried all sorts of things and i cannot get the button to change the value of X in my while loop. Can someone please explain how to do this or link a video/guide that does a good job explaining this to a novice?</p>
  
  <p>Thanks</p>