First, define get and set functions:
# Basic examples for get and set value functions def get_value(): # will only be used to get the initial value return httpx.get(f"http://{ip}/api/get-value").json()["value"] def set_value(value): httpx.get(f"http://{ip}/api/set-value?nedge={value}")
import ipywidgets as widgets from IPython.display import display # Step 2: Define the widget components value_display = widgets.IntText(value=get_value(), description='Value:', disabled=False) plus_button = widgets.Button(description='+') minus_button = widgets.Button(description='-') def on_value_change(change): set_value(change['new']) value_display.observe(on_value_change, names='value') # Step 4: Define the update functions def on_plus_button_clicked(b): value_display.value += 1 def on_minus_button_clicked(b): value_display.value -= 1 # Step 5: Bind the update functions to the buttons plus_button.on_click(on_plus_button_clicked) minus_button.on_click(on_minus_button_clicked) # Step 6: Display the widgets widgets_layout = widgets display(value_display, plus_button, minus_button)