Skip to content

Instantly share code, notes, and snippets.

@NehaAkashDeo
Created July 28, 2020 18:12
Show Gist options
  • Select an option

  • Save NehaAkashDeo/6c37bce82afc20aa97e6432485362590 to your computer and use it in GitHub Desktop.

Select an option

Save NehaAkashDeo/6c37bce82afc20aa97e6432485362590 to your computer and use it in GitHub Desktop.
ipywidgets
ipython
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import widgets\n",
"from IPython.display import display, clear_output\n",
"\n",
"text = widgets.Text()\n",
"display(text)\n",
"output = widgets.Output()\n",
"display(output)\n",
"def handle_submit(sender):\n",
" with output:\n",
" clear_output()\n",
" print('\\n'.join([text.value] * 2 )) \n",
"\n",
"text.on_submit(handle_submit)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"# You could also pass in continuous_update=False to only send \n",
"# the new value when pressing enter or leaving the textbox\n",
"t = widgets.Text(continuous_update=False)\n",
"\n",
"def value_changed(change):\n",
" # change.new contains the new value\n",
" print('new value: ' + change.new)\n",
"\n",
"# call the value_changed function when t.value changes\n",
"t.observe(value_changed, 'value')\n",
"\n",
"display(t)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment