title: ipywidgets - display next value in list after clicking
body: <p>I'm trying to use <code>ipywidgets</code> in order to display next value in my list (in Jupyter notebook) given as <code>display_vals</code> after clicking the button. However, with the following code snippet, I got error as </p>
  
  <pre><code>local variable 'i' referenced before assignment
  </code></pre>
  
  <p>Here is the snippet that I have</p>
  
  <pre><code>from IPython.display import display, clear_output
  import ipywidgets as widgets
  
  button = widgets.Button(description="Click Me!")
  display(button)
  
  display_vals = ['a', 'b', 'c']
  i = 0
  
  def on_button_clicked(b):
      print(display_vals[i])
      clear_output()
      i += 1
  
  button.on_click(on_button_clicked)
  </code></pre>
  
  <p>I guess I just don't know the way to parse my variable when button gets clicked.</p>