If you wish the styling of widgets to make use of colors and styles defined by the environment (to be consistent with e.g. a notebook theme), some widgets enable choosing in a list of pre-defined styles.
For example, the Button
widget has a button_style
attribute that may take 5 different values:
'primary'
'success'
'info'
'warning'
'danger'
besides the default empty string ''.
from ipywidgets import Button, IntSlider
Button(description='Danger Button', button_style='danger')
style
attribute¶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.
b1 = Button(description='Custom color')
b1.style.button_color = 'lightgreen'
b1
You can get a list of the style attributes for a widget with the keys
property.
b1.style.keys
Just like the layout
attribute, widget styles can be assigned to other widgets.
b2 = Button()
b2.style = b1.style
b2
Widget styling attributes are specific to each widget type.
s1 = IntSlider(description='Blue handle')
s1.style.handle_color = 'lightblue'
s1
There is a list of all style keys.