I want to create a toggle button to display some output and clear it when switched in jupyter notebook using ipywidget.
I tried to do it using widgets.Output(). This however displays empty lines as I click more and more times.
Please help me out.
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)