#!/usr/bin/env python # coding: utf-8 # In[1]: from IPython.html.widgets import FloatText, FloatSlider, Button from IPython.display import display from IPython.utils.traitlets import link widgets = [] for x in list('abcdef'): widgets.append(FloatText(description=x)) a = FloatSlider() b = FloatSlider() link((a, 'value'), (b, 'value')) threads = [] def go(sender): def thread_code(): from time import sleep from random import random while len(threads) > 0: for w in widgets: w.value = random() sleep(0.01) from threading import Thread thread = Thread(target=thread_code) threads.append(thread) thread.start() go_btn = Button(description="Go!") go_btn.on_click(go) def stop(sender): del threads[:] stop_btn = Button(description="Stop") stop_btn.on_click(stop) display(*widgets) display(a,b) display(go_btn) display(stop_btn)