title: Make a function that wait a parameter to change triggered by button
body: <p>The following is a program that does not make sense, but I want to do something similar in a larger code. One function is called and I want it to wait for a change in a parameter, where the change is triggered by a button. Running this code, when the OK button is pressed it doesn't allow for another button to be pressed and it freezes. Also before anything, I get the error: name 'boton' is assigned to before global declaration. Thanks for reading. Saludos.</p>
  
  <pre><code>from Tkinter import *
  import time
  master = Tk()
  
  def callback():
      w1['text']="this"
      while boton==0:
          time.sleep(1)
      w1['text']="and then this"
  
  def switch():
      if boton==0:
          global boton
          boton=1
      if boton==1:
          global boton
          boton=0
  
  boton=0
  w1 = Label(master, text="")
  w1.grid(row=0, column=0)
  e1 = Entry(master)
  e1.grid(row=0, column=1)
  b = Button(master, text="OK", command=callback)
  b.grid(row=1, column=0)
  b2 = Button(master, text="switch", command=switch)
  b2.grid(row=1, column=1)
  
  mainloop()
  </code></pre>