Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python ipywidgets ToggleButton Style Color

I want to change the button color of a ipywidget ToggleButton. In the docs it is described as:

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
)

The only way I can see is with button_style, which however has just the predefined options seen in the code. Is there a way to define such a preset on your own with custom button colors? I also tried styling it with CSS. button_color, description_color as well as background_color all did not work.

I cannot change the toggle button color to any other than the predefined color schemes ('success', 'info', 'warning', 'danger' or ''). Also jumping into the package, I did not find where they are defined. That is why I am not able to overwrite them.

Also, I am working in a Jupyter Notebook.

Kind regards, Timo

like image 910
TimoBe Avatar asked Feb 11 '26 02:02

TimoBe


1 Answers

Widgets have a style attribute which might help you achieve what you want, read more here:

https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Styling.html#The-style-attribute

The attributes will vary by widget type. Unfortunately the keys option for ToggleButtons does not list button_color, so it does not look like the color can be modified this way.

like image 87
ac24 Avatar answered Feb 13 '26 15:02

ac24



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!