<jupyter_start><jupyter_text>Button eventhttps://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Events.html<jupyter_code>print(widgets.Button.on_click.__doc__)
button = widgets.Button(description="Click Me!", button_style="primary")
output = widgets.Output()

def on_button_clicked(b):
    with output:
        print("Button clicked.")

button.on_click(on_button_clicked)

widgets.VBox([button, output])<jupyter_output><empty_output><jupyter_text>Other widget eventshttps://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Events.htmlTraitlet-events<jupyter_code>print(widgets.Widget.observe.__doc__)<jupyter_output><empty_output><jupyter_text>First example<jupyter_code>buttons = widgets.ToggleButtons(
    value=None,
    options=["Show", "Hide", "Close"],
    button_style="primary",
)
buttons.style.button_width = "80px"

html = widgets.HTML(
    value='<img src="https://earthengine.google.com/static/images/earth-engine-logo.png" width="100" height="100">'
)

vbox = widgets.VBox([buttons, html])
vbox
def handle_btn_click(change):
    
    if change['new'] == 'Show':
        vbox.children = [buttons, html]
    elif change['new'] == 'Hide':
        vbox.children = [buttons]
    elif change['new'] == 'Close':
        buttons.close()
        html.close()
        vbox.close()
        
buttons.observe(handle_btn_click, "value")<jupyter_output><empty_output><jupyter_text>Second example<jupyter_code>dropdown = widgets.Dropdown(
    options=["Landsat", "Sentinel", "MODIS"],
    value=None,
    description="Satellite:",
    style={"description_width": "initial"},
    layout=widgets.Layout(width="250px")
)

btns = widgets.ToggleButtons(
    value=None,
    options=["Apply", "Reset", "Close"],
    button_style="primary",
)
btns.style.button_width = "80px"

output = widgets.Output()

box = widgets.VBox([dropdown, btns, output])
box
def dropdown_change(change):
    if change['new']:
        with output:
            output.clear_output()
            print(change['new'])
            
dropdown.observe(dropdown_change, "value")
def button_click(change):
    with output:
        output.clear_output()
        if change['new'] == "Apply":
            if dropdown.value is None:
                print("Please select a satellie from the dropdown list.")
            else:
                print(f"You selected {dropdown.value}")
        elif change['new'] == 'Reset':
            dropdown.value = None
        else:
            box.close()
            
btns.observe(button_click, "value")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14668769716088328, 'fraction_numerical': 0.006703470031545741, 'mean_word_length': 3.7867924528301886, 'pattern_counts': {'":': 2, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '83220', 'license': 'MIT', 'n_tokens_mistral': 849, 'n_tokens_neox': 821, 'n_words': 128, 'path': 'examples/ipywidgets_events.ipynb', 'repo_name': 'HJRubin/nclpy', 'size': '2536'}