I would like to clear the previous output when the widget is rerun.
for example
from IPython.display import display, clear_output
import ipywidgets as widgets
from datetime import datetime, timedelta
button = widgets.Button(description='RUN',button_style='info')
def on_button_clicked(b):
# DO SOMETHING #
out = widgets.Output()
out.clear_output(wait=True)
out.append_stdout(f'Ran at {datetime.now()}')
display(out)
button.on_click(on_button_clicked)
widgets.VBox([button])
Every time i click on the RUN button it "appends" the print statement
I also tried this:
button = widgets.Button(description='RUN',button_style='info')
def on_button_clicked(b):
# DO SOMETHING #
out = widgets.Output()
out.clear_output(wait=True)
with out:
print(f'Ran at {datetime.now()}')
display(out)
button.on_click(on_button_clicked)
widgets.VBox([button])
NameError: name 'button' is not defined