title: How to create a toogle button to show and clear output using ipywidgets?
body: <p>I want to create a toggle button to display some output and clear it when switched in jupyter notebook using <code>ipywidget</code>.</p>
  
  <p>I tried to do it using <code>widgets.Output()</code>. This however displays empty lines as I click more and more times.</p>
  
  <p>Please help me out.</p>
  
  <pre class="lang-py prettyprint-override"><code>import ipywidgets as w
  toggle = w.ToggleButton(description='click me')
  
  out = w.Output()
  
  def fun(obj):
      global out
      with out:
          display('asd')
      if obj['new']:  
          display(out)
      else:
          out.clear_output()
          out = w.Output()
  
  toggle.observe(fun, 'value')
  display(toggle)
  
  </code></pre>