title: Why does the my function called by ipywidget button not return an output?
body: <p>I'm using a button to call a function, but the output of the function doesn't seem to be saved. </p>
  
  <p>I'm creating an interactive jupyter notebook which is design to execute functions when a buttons are clicked. For example, the first button called "<code>Get data</code>", which would create new variables. Then a second button, "<code>Analyze data</code>" would do some analysis on the variables. The problem is that the output of "<code>Get data</code>" is not being saved outside the function.</p>
  
  <pre class="lang-py prettyprint-override"><code># GET DATA
  get_data_button = widgets.Button(description='Get Data')
  
  def get_data(b):
  
      data = 10
      print(data)
  
      return data
  
  # DISPLAY BUTTON
  get_data_button.on_click(get_data)
  display(get_data_button)
  </code></pre>
  
  <p>I'm expecting that after the function I could do </p>
  
  <pre class="lang-py prettyprint-override"><code>print(data)
  </code></pre>
  
  <p>and return 10</p>
  
  <p>instead it says:</p>
  
  <blockquote>
    <p>name 'data' is not defined</p>
  </blockquote>