import threading
from IPython.display import display, HTML
import ipywidgets as widgets
import time
def thread_func(out):
i = 0
while True:
out.clear_output()
out.append_stdout('{}\n'.format(i))
i += 1
time.sleep(1)
out = widgets.Output()
thread = threading.Thread(
target=thread_func,
args=(out,))
thread.start()
display(out)