Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import wraps
- def yield_for_change(widget, attribute):
- def f(iterator):
- @wraps(iterator)
- def inner():
- i = iterator()
- def next_i(change):
- try:
- i.send(change.new)
- except StopIteration as e:
- widget.unobserve(next_i, attribute)
- widget.observe(next_i, attribute)
- # start the generator
- next(i)
- return inner
- return f
- from ipywidgets import Button
- button=Button()
- def on_button_clicked():
- print("Button clicked.")
- @yield_for_change(button, 'value')
- def f():
- for i in range(10):
- print('did work %s'%i)
- x = yield
- button.on_click(on_button_clicked)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement