title: Pause Jupyter Notebook widgets, waiting for user input
body: <p>I have the same issue as TheInterestedOne asked <a href="https://stackoverflow.com/questions/54629964/how-to-pause-jupyter-notebook-widgets-waiting-for-user-input">here</a>. </p>
  
  <p>I need to create two buttons for the user, and suggest that the user clicks one of the two buttons in the loop; so that the next iteration of the loop occurs only after the user's choice. </p>
  
  <p>I read <a href="https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Asynchronous.html" rel="noreferrer">this source</a>, but I can't make it work for buttons. I don't understand, how the widget attribute changes in the case of using buttons.</p>
  
  <pre><code>from functools import wraps
  def yield_for_change(widget, attribute):
      def f(iterator):
          @wraps(iterator)
          def inner():
              i = iterator()
              def next_i(change):
                  try:
                      i.send(change.new)
                  except StopIteration as e:
                      widget.unobserve(next_i, attribute)
              widget.observe(next_i, attribute) //**button.on_click(on_button_clicked) 
                                                                  may be?**
              # start the generator
              next(i)
          return inner
      return f
  
  
  from ipywidgets import Button
  button=Button()
  
  
  def on_button_clicked():
      print("Button clicked.")
  
  
  @yield_for_change(button, 'value')
  def f():
      for i in range(10):
          print('did work %s'%i)
          x = yield
          button.on_click(on_button_clicked)
  </code></pre>