如何控制ipywidgets.ToggleButtons按钮的宽度

How to control the width of buttons of ipywidgets.ToggleButtons

一个基本的切换按钮看起来像

widgets.ToggleButtons(
    options=['Slow', 'Regular', 'Fast'],
    description='Speed:',
    disabled=False,
    button_style='', # 'success', 'info', 'warning', 'danger' or ''
    tooltips=['Description of slow', 'Description of regular', 'Description of fast'],
#     icons=['check'] * 3
)

代码来自https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#ToggleButtons

但这会为小文本生成相当大的按钮。

我一直在尝试不同的布局选项,但这只会影响按钮的容器。

documentation所说

While the layout attribute only exposes layout-related CSS properties for the top-level DOM element of widgets, the style attribute is used to expose non-layout related styling attributes of widgets.

However, the properties of the style attribute are specific to each widget type.

解决之道在于style={"button_width": "50px"}

例子

widgets.ToggleButtons(
    options=['A','B', 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCC'],
    disabled=False,
    button_style='info', # 'success', 'info', 'warning', 'danger' or ''
    layout=widgets.Layout(width='auto'),
    style={"button_width": "auto"},
    #     icons=['check'] * 3
)

widgets.ToggleButtons(
    options=['A','B', 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCC'],
    disabled=False,
    button_style='warning', # 'success', 'info', 'warning', 'danger' or ''
    layout=widgets.Layout(width='auto'),
    style={"button_width": "50px"},
    #     icons=['check'] * 3
)