You may have noticed that long descriptions are truncated. This is because the description length is, by default, fixed.
from ipywidgets import IntSlider
IntSlider(description='A too long description')
If you need more flexibility to lay out widgets and descriptions, you can use Label widgets directly.
from ipywidgets import HBox, Label
HBox([Label('A too long description'), IntSlider()])
You can change the length of the description to fit the description text. However, this will make the widget itself shorter. You can change both by adjusting the description width and the widget width using the widget's style.
style = {'description_width': 'initial'}
IntSlider(description='A too long description', style=style)
Most of the core-widgets have default heights and widths that tile well together. This allows simple layouts based on the HBox
and VBox
helper functions to align naturally:
from ipywidgets import Button, HBox, VBox
words = ['correct', 'horse', 'battery', 'staple']
items = [Button(description=w) for w in words]
left_box = VBox([items[0], items[1]])
right_box = VBox([items[2], items[3]])
HBox([left_box, right_box])
Widgets such as sliders and text inputs have a description attribute that can render Latex Equations. The Label
widget also renders Latex equations.
from ipywidgets import IntSlider, Label
IntSlider(description=r'\(\int_0^t f\)')
Label(value=r'\(e=mc^2\)')
Sliders have a readout field which can be formatted using Python's Format Specification Mini-Language. If the space available for the readout is too narrow for the string representation of the slider value, a different styling is applied to show that not all digits are visible.