title: Matplotlib, button to close a loop, python
body: <p>I have a plot that allows user to click on a data point. Then it generates a continuous loop that was supposed to be closed by clicking on the close button. The example below will trigger a print message of "Still Looping" every 1second. Then I created a button hoping to close the loop by changing loopBool to True. But it doesn't work because once the loop starts I am not able to interact with the figure window. How can I solve this? Many thanks</p>
  
  <pre><code>import numpy as np
  from matplotlib import pyplot as plt
  import time
  import matplotlib.widgets as widgets
  fig, ax = plt.subplots()
  # it is not always column 0 and 1
  sctPlot = ax.scatter([-0.3,0,0.3], [0.3,0.3,0.3],  c="blue", picker = 2, s=[50]*3)
  fig.subplots_adjust(bottom=0.3, left=0.1)
  plt.grid(False)
  plt.axis([-0.6, 0.6, -0.6, 0.6])
  
  loopBool = True
  
  def closeLooping(event):
      global loopBool
      loopBool = False
  
  def looping(event):
      global loopBool
      while (loopBool == True):
          print "Still Looping!"
          time.sleep(1)
      print "Stop!!"
  
  axCloseButton = plt.axes([0.1, 0.15, 0.2, 0.06])
  bClose = Button(axCloseButton, "Close", color = axcolor, hovercolor = '0.975')
  bClose.on_clicked(closeLooping)
  
  
  fig.canvas.mpl_connect('pick_event', looping)
  </code></pre>