<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Interactive Widgets
Using interact
Source Link
Step1:  Note the semicolon
Step2:  Booleans create checkbox
Step3:  Using decorators
Step4:  From Portilla's notes
This examples clarifies how interact process its keyword arguments
Step5:  Function Annotations
Step6:  multiple instances remain in sync!
Step7:  There are client-server nuances!
Step8:  Source 
With mroe text descriptions
Step9:  This is not working!
<ASSISTANT_TASK:>
Python Code:
# Start with some imports!
from __future__ import print_function
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets
# Very basic function
def f(x):
    return x
help(interact)
Explanation: Interactive Widgets
Using interact
Source Link
End of explanation
# Generate a slider to interact with
interact(f, x=10);
interact(f, x=10,);
Explanation: Note the semicolon
End of explanation
# Booleans generate check-boxes
interact(f, x=True);
# Strings generate text areas
interact(f, x='Hi there!');
Explanation: Booleans create checkbox
End of explanation
# Using a decorator!
@interact(x=True, y=1.0)
def g(x, y):
    return (x, y)
# Again, a simple function
def h(p, q):
    return (p, q)
interact(h, p=5, q=fixed(20));
interact(f, x=widgets.IntSlider(min=-10., max=30, value=10));
Explanation: Using decorators
End of explanation
# Min,Max slider with Tuples
interact(f, x=(0,4));
# (min, max, step)
interact(f, x=(0,8,2));
interact(f, x=(0.0,10.0));
interact(f, x=(0.0,10.0,0.01));
@interact(x=(0.0,20.0,0.5))
def h(x=5.5):
    return x
interact(f, x=('apples','oranges'));
interact(f, x={'one': 10, 'two': 20});
Explanation: From Portilla's notes
This examples clarifies how interact process its keyword arguments:
If the keyword argument is a Widget instance with a value attribute, that widget is used. Any widget with a value attribute can be used, even custom ones.
Otherwise, the value is treated as a widget abbreviation that is converted to a widget before it is used.
The following table gives an overview of different widget abbreviations:
<table class="table table-condensed table-bordered">
  <tr><td><strong>Keyword argument</strong></td><td><strong>Widget</strong></td></tr>  
  <tr><td>`True` or `False`</td><td>Checkbox</td></tr>  
  <tr><td>`'Hi there'`</td><td>Text</td></tr>
  <tr><td>`value` or `(min,max)` or `(min,max,step)` if integers are passed</td><td>IntSlider</td></tr>
  <tr><td>`value` or `(min,max)` or `(min,max,step)` if floats are passed</td><td>FloatSlider</td></tr>
  <tr><td>`('orange','apple')` or `{'one':1,'two':2}`</td><td>Dropdown</td></tr>
</table>
End of explanation
def f(x:True): # python 3 only
    return x
from IPython.utils.py3compat import annotate
@annotate(x=True)
def f(x):
    return x
interact(f);
def f(a, b):
    return a+b
w = interactive(f, a=10, b=20)
type(w)
w.children
from IPython.display import display
display(w)
w.kwargs
w.result
from ipywidgets import *
IntSlider()
from IPython.display import display
w = IntSlider()
display(w)
display(w)
Explanation: Function Annotations
End of explanation
w.close()
w = IntSlider()
display(w)
w.value
w.value = 100
w.keys
Text(value='Hello World!')
Text(value='Hello World!', disabled=True)
from traitlets import link
a = FloatText()
b = FloatSlider()
display(a,b)
mylink = link((a, 'value'), (b, 'value'))
mylink.unlink()
print(widgets.Button.on_click.__doc__)
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)
text = widgets.Text()
display(text)
def handle_submit(sender):
    print(text.value)
text.on_submit(handle_submit)
print(widgets.Widget.on_trait_change.__doc__)
print(widgets.obse)
int_range = widgets.IntSlider()
display(int_range)
def on_value_change(name, value):
    print(value)
int_range.on_trait_change(on_value_change, 'value')
import traitlets
# Create Caption
caption = widgets.Label(value = 'The values of slider1 and slider2 are synchronized')
# Create IntSlider
slider1 = widgets.IntSlider(description='Slider 1')
slider2 =  widgets.IntSlider(description='Slider 2')
# Use trailets to link
l = traitlets.link((slider1, 'value'), (slider2, 'value'))
# Display!
display(caption, slider1, slider2)
# Create Caption
caption = widgets.Latex(value = 'Changes in source values are reflected in target1')
# Create Sliders
source = widgets.IntSlider(description='Source')
target1 = widgets.IntSlider(description='Target 1')
# Use dlink
dl = traitlets.dlink((source, 'value'), (target1, 'value'))
display(caption, source, target1)
# May get an error depending on order of cells being run!
l.unlink()
dl.unlink()
Explanation: multiple instances remain in sync!
End of explanation
# NO LAG VERSION
caption = widgets.Latex(value = 'The values of range1 and range2 are synchronized')
range1 = widgets.IntSlider(description='Range 1')
range2 =  widgets.IntSlider(description='Range 2')
l = widgets.jslink((range1, 'value'), (range2, 'value'))
display(caption, range1, range2)
# NO LAG VERSION
caption = widgets.Latex(value = 'Changes in source_range values are reflected in target_range1')
source_range = widgets.IntSlider(description='Source range')
target_range1 = widgets.IntSlider(description='Target range ')
dl = widgets.jsdlink((source_range, 'value'), (target_range1, 'value'))
display(caption, source_range, target_range1)
l.unlink()
dl.unlink()
import ipywidgets as widgets
# Show all available widgets!
widgets.Widget.widget_types.values()
widgets.FloatSlider(
    value=7.5,
    min=5.0,
    max=10.0,
    step=0.1,
    description='Test:',
)
widgets.FloatSlider(
    value=7.5,
    min=5.0,
    max=10.0,
    step=0.1,
    description='Test',
    orientation='vertical',
)
widgets.FloatProgress(
    value=7.5,
    min=5.0,
    max=10.0,
    step=0.1,
    description='Loading:',
)
widgets.BoundedFloatText(
    value=7.5,
    min=5.0,
    max=10.0,
    description='Text:',
)
widgets.FloatText(
    value=7.5,
    description='Any:',
)
widgets.ToggleButton(
    description='Click me',
    value=False,
)
widgets.Checkbox(
    description='Check me',
    value=True,
)
widgets.Valid(
    value=True,
)
from IPython.display import display
w = widgets.Dropdown(
    options=['1', '2', '3'],
    value='2',
    description='Number:',
)
display(w)
# Show value
w.value
w = widgets.Dropdown(
    options={'One': 1, 'Two': 2, 'Three': 3},
    value=2,
    description='Number:')
display(w)
w.value
widgets.RadioButtons(
    description='Pizza topping:',
    options=['pepperoni', 'pineapple', 'anchovies'],
)
widgets.Select(
    description='OS:',
    options=['Linux', 'Windows', 'OSX'],
)
widgets.ToggleButtons(
    description='Speed:',
    options=['Slow', 'Regular', 'Fast'],
)
w = widgets.SelectMultiple(
    description="Fruits",
    options=['Apples', 'Oranges', 'Pears'])
display(w)
w.value
widgets.Text(
    description='String:',
    value='Hello World',
)
widgets.Textarea(
    description='String:',
    value='Hello World',
)
widgets.Latex(
    value="$$\\frac{n!}{k!(n-k)!}$$",
)
widgets.HTML(
    value="Hello <b>World</b>"
)
widgets.Button(description='Click me')
Explanation: There are client-server nuances!
End of explanation
%%html
<style>
.example-container { background: #999999; padding: 2px; min-height: 100px; }
.example-container.sm { min-height: 50px; }
.example-box { background: #9999FF; width: 50px; height: 50px; text-align: center; vertical-align: middle; color: white; font-weight: bold; margin: 2px;}
.example-box.med { width: 65px; height: 65px; }   
.example-box.lrg { width: 80px; height: 80px; }   
</style>
import ipywidgets as widgets
from IPython.display import display
button = widgets.Button(
    description='Hello World!',
    width=100, # Integers are interpreted as pixel measurements.
    height='2em', # em is valid HTML unit of measurement.
    color='lime', # Colors can be set by name,
    background_color='#0022FF', # and also by color code.
    border_color='cyan')
display(button)
Explanation: Source 
With mroe text descriptions
End of explanation
from IPython.display import display
float_range = widgets.FloatSlider()
string = widgets.Text(value='hi')
container = widgets.Box(children=[float_range, string])
container.border_color = 'red'
container.border_style = 'dotted'
container.border_width = 3
display(container) # Displays the `container` and all of it's children.
container = widgets.Box()
container.border_color = 'red'
container.border_style = 'dotted'
container.border_width = 3
display(container)
int_range = widgets.IntSlider()
container.children=[int_range]
name1 = widgets.Text(description='Location:')
zip1 = widgets.BoundedIntText(description='Zip:', min=0, max=99999)
page1 = widgets.Box(children=[name1, zip1])
name2 = widgets.Text(description='Location:')
zip2 = widgets.BoundedIntText(description='Zip:', min=0, max=99999)
page2 = widgets.Box(children=[name2, zip2])
accord = widgets.Accordion(children=[page1, page2], width=400)
display(accord)
accord.set_title(0, 'From')
accord.set_title(1, 'To')
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')
display(widgets.Text(description="a:"))
display(widgets.Text(description="aa:"))
display(widgets.Text(description="aaa:"))
display(widgets.Text(description="a:"))
display(widgets.Text(description="aa:"))
display(widgets.Text(description="aaa:"))
display(widgets.Text(description="aaaaaaaaaaaaaaaaaa:"))
display(widgets.Text(description="a:"))
display(widgets.Text(description="aa:"))
display(widgets.Text(description="aaa:"))
display(widgets.Text())
buttons = [widgets.Button(description=str(i)) for i in range(3)]
display(*buttons)
container = widgets.HBox(children=buttons)
display(container)
container = widgets.VBox(children=buttons)
display(container)
container = widgets.FlexBox(children=buttons)
display(container)
w1 = widgets.Latex(value="First line")
w2 = widgets.Latex(value="Second line")
w3 = widgets.Latex(value="Third line")
display(w1, w2, w3)
w2.visible=None
w2.visible=False
w2.visible=True
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')
Explanation: This is not working!
End of explanation
<END_TASK>