Text wrapping
The panel keeps narrowing and widening as the wrapping rules change. Watch the spaces after First, the line break before Second, and where the long word breaks.
Triple quotes keep line breaks and spaces. Call .trim() to remove whitespace from both ends of the string. Use r""" when you want braces treated as literal text.
Choose a wrapping rule
Text starts with whitespace-normal. Apply a utility to the text or its parent Box, or bind white_space={mode} to change the rule during an animation.
| Utility | Spaces and tabs | Explicit line breaks | Wraps at the box edge |
|---|---|---|---|
whitespace-normal | Collapse | Collapse | Yes |
whitespace-pre-wrap | Keep | Keep | Yes |
whitespace-pre-line | Collapse | Keep | Yes |
whitespace-nowrap | Collapse | Collapse | No |
whitespace-pre | Keep | Keep | No |
Use wrap-anywhere or wrap-break-word to break a long word that would overflow a fixed width. To clip the overflow, use overflow-x-hidden. Code defaults to whitespace-pre and keeps source line numbers when a line wraps.
Choose a font
Set font_size={24pt} and font={Font(["sans-serif"])} to select a font family and size.
Set font_weight={650} for heavier text. Weight ranges from 1 to 1000 and defaults to 400. Variable fonts can use weights between their named styles.