Last active
June 13, 2024 16:56
-
-
Save fomightez/485a67a8e2c183e71e49aab0bd0db35b to your computer and use it in GitHub Desktop.
Proposed Updated versions of SO 40165257/8508004 to work in all current Jupyter tech https://stackoverflow.com/a/40165257/8508004
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#For https://stackoverflow.com/a/40165257/8508004 | |
import ipywidgets as widgets | |
from IPython.display import HTML | |
w = widgets.Dropdown( | |
options=['Addition', 'Multiplication', 'Subtraction', 'Division'], | |
value='Addition', | |
description='Task:', | |
) | |
def on_change(change): | |
if change['type'] == 'change' and change['name'] == 'value': | |
status_output.update(HTML("changed to %s" % change['new'])) | |
w.observe(on_change) | |
status_output = display(HTML("STATUS WILL UPDATE HERE"), display_id=True) | |
display(w) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#For https://stackoverflow.com/a/40165257/8508004 | |
import ipywidgets as widgets | |
from IPython.display import display | |
output = widgets.Output() | |
w = widgets.Dropdown( | |
options=['Addition', 'Multiplication', 'Subtraction', 'Division'], | |
value='Addition', | |
description='Task:', | |
) | |
def on_change(change): | |
if change['type'] == 'change' and change['name'] == 'value': | |
with output: | |
output.clear_output() # from 'Output widgets: leveraging Jupyter’s display system' https://ipywidgets.readthedocs.io/en/latest/examples/Output%20Widget.html | |
print("changed to %s" % change['new']) | |
w.observe(on_change) | |
display(w, output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment