[Python] How to have an ipywidgets.ToggleButtons with multiple buttons using the same label

Discussão em 'Python' iniciado por Stack, Junho 12, 2025.

  1. Stack

    Stack Membro Participativo

    By default, all the options for the buttons must be unique.

    options=["label1","label2",...]


    You can however provide a list of tuples like this

    options=[("label1",value1), ("label2",value2),]


    And that is accepted.

    However, if you provide this

    options=[("label1",value1), ("label2",value2),("label1",value3)]


    It displays well, behind the scenes provides the good .value and .index, but visually it selects the first "label1" when you click the second "label1".

    [​IMG]

    How can I work around that limitation?

    Code:

    import ipywidgets as widgets

    realoptions="One word in different location is possibly a different word".split()
    options=realoptions

    t=widgets.ToggleButtons(
    options=options,
    description='Choose:',
    disabled=False,
    button_style='', # 'success', 'info', 'warning', 'danger' or ''
    #tooltips=['Description of b1', 'Description of b2', ... ],
    # icons=['check'] * 3
    )
    t

    Continue reading...

Compartilhe esta Página