Skip to content

Instantly share code, notes, and snippets.

@fomightez
Last active June 13, 2024 16:56
Show Gist options
  • Save fomightez/485a67a8e2c183e71e49aab0bd0db35b to your computer and use it in GitHub Desktop.
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
#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)
#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