In [1]:
from ipywidgets import interact, fixed
@interact(x=True, y=1.0, z=fixed(20))
def g(x, y, z):
return (x, y, z)
In [2]:
from ipywidgets import interact, fixed
@interact(x={'one': 10, 'two': 20}, y=(-1.0, 10.0, 2.5))
def g(x, y):
return (x, y)
In [3]:
import ipywidgets as widgets
widgets.FloatSlider(
value=7.5,
min=5.0,
max=10.0,
step=0.1,
description='Test',
orientation='vertical',
)
In [4]:
widgets.FloatProgress(
value=7.5,
min=5.0,
max=10.0,
step=0.1,
description='Loading:',
)
In [5]:
widgets.ToggleButton(
description='Click me',
value=False,
)
In [6]:
widgets.Valid(
value=True,
)
In [7]:
widgets.RadioButtons(
description='Pizza topping:',
options=['pepperoni', 'pineapple', 'anchovies'],
)
In [8]:
widgets.ToggleButtons(
description='Speed:',
options=['Slow', 'Regular', 'Fast'],
)
Keyword argument | Widget |
`True` or `False` | Checkbox |
`'Hi there'` | Text |
`value` or `(min,max)` or `(min,max,step)` if integers are passed | IntSlider |
`value` or `(min,max)` or `(min,max,step)` if floats are passed | FloatSlider |
`('orange','apple')` or `{'one':1,'two':2}` | Dropdown |
In [9]:
from ipywidgets import interactive
def f(x, y):
return x, y
widget = interactive(f, x=(0, 100, 5), y=('gauche', 'droite', 'haut', 'bas'))
In [10]:
widget
In [11]:
widget.kwargs
Out[11]:
In [12]:
widget.children[0].value = 50
In [22]:
from IPython.display import display
name = widgets.Text(description='Name:', padding=4)
color = widgets.Dropdown(description='Color:', padding=4, options=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])
page1 = widgets.Box(children=[name, color], padding=4)
age = widgets.IntSlider(description='Age:', padding=4, min=0, max=120, value=50)
gender = widgets.RadioButtons(description='Gender:', padding=4, options=['male', 'female'])
page2 = widgets.Box(children=[age, gender], padding=4)
tabs = widgets.Tab(children=[page1, page2])
display(tabs)
tabs.set_title(0, 'Name')
tabs.set_title(1, 'Details')
In [14]:
from IPython.display import display
form = widgets.VBox()
first = widgets.Text(description="First:")
last = widgets.Text(description="Last:")
student = widgets.Checkbox(description="Student:", value=False)
school_info = widgets.VBox(visible=False, children=[
widgets.Text(description="School:"),
widgets.IntText(description="Grade:", min=0, max=12)
])
pet = widgets.Text(description="Pet:")
form.children = [first, last, student, school_info, pet]
display(form)
def on_student_toggle(name, value):
if value:
school_info.visible = True
else:
school_info.visible = False
student.on_trait_change(on_student_toggle, 'value')
In [15]:
from IPython.display import display
button = widgets.Button(description="Click Me!")
display(button)
def on_button_clicked(b):
print("Button clicked.")
button.on_click(on_button_clicked)
In [ ]: