4

I'm trying to temporarily change the color of a button in a ipywidgets.ToggleButtons' list, but I can't access the individual elements in a ToggleButtons' instance.

Hence I'm missing a def get_child_of() kind of function

from IPython.display import display
import ipywidgets as widgets


# Create ToggleButtons
class_buttons = widgets.ToggleButtons(
    options=['blender', 'boiling-water', 'book'],
    description='Classes:')

# Create clickable Button
next_button = widgets.Button(
    description='Next')

@next_button.on_click
def next_audio(b):    
    # TODO: Somehow get the desired child
    child = get_child_of(class_buttons, 'blender')
    child.style.button_color = 'lightgreen'

# Create VBox
tab = widgets.VBox(children=[class_buttons,
                     next_button])

# Display everything
display(tab)
Marc Moreaux
  • 190
  • 1
  • 9
  • There's nothing in the ipywidgets documentation to suggest you can set the style of these buttons individually, only as a whole (e.g. `class_buttons.button_style = 'warning'`). So it might not be possible on the current version. The normal function to get a 'child' is the `.children` variable, but this is not defined for ToggleButtons. – ac24 Mar 27 '19 at 11:50

0 Answers0