Skip to content

Rich text

Combines pz.span(text, color=, size=, font=, weight=, italic=, bg=, underline=, strikethrough=, link=) fragments into a single block of text that wraps as a whole. Clicking a span with link sends that value.

pz.rich_text · Category: Content · Full reference →

Rich textRich text
  • For inline highlights, mentions, search matches and short formatted messages.
import pyzed as pz
pz.rich_text([
pz.span("rich_text "),
pz.span("mixes ", color="#e5c07b"),
pz.span("styles", weight="bold", underline=True),
pz.span(" on one line, with "),
pz.span(" code ", font="IBM Plex Mono", bg="#3b414d", radius=4),
pz.span(" and "),
pz.span("links", color="#74ade8", underline=True, link="https://iced.rs"),
], size=18, width=460)
Rich text: weight="bold"Rich text: weight="bold"
weight="bold"
Code
pz.rich_text([pz.span("Some "), pz.span("bold", weight="bold"), pz.span(" text")], size=16)
Rich text: italic=TrueRich text: italic=True
italic=True
Code
pz.rich_text([pz.span("Some "), pz.span("italic", italic=True), pz.span(" text")], size=16)
Rich text: color=Rich text: color=
color=
Code
pz.rich_text([pz.span("Some "), pz.span("colored", color="#e5c07b"), pz.span(" text")], size=16)
Rich text: underline=TrueRich text: underline=True
underline=True
Code
pz.rich_text([pz.span("Some "), pz.span("underlined", underline=True), pz.span(" text")], size=16)
Rich text: strikethrough=TrueRich text: strikethrough=True
strikethrough=True
Code
pz.rich_text([pz.span("Some "), pz.span("struck", strikethrough=True), pz.span(" text")], size=16)
Rich text: bg=, radius=Rich text: bg=, radius=
bg=, radius=
Code
pz.rich_text([pz.span("Run "), pz.span(" pyzed new ", font="mono", bg="#3b414d", color="#e6e6e6", radius=4)], size=16)
Rich text: link=Rich text: link=
link=
Code
pz.rich_text([pz.span("Read "), pz.span("the docs", color="#74ade8", underline=True, link="https://iced.rs")], size=16)
Rich text: size=Rich text: size=
size=
Code
pz.rich_text([pz.span("small ", size=12), pz.span("big", size=24, weight="bold")])

Rich text has no events of its own: it shows what you give it. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.

rich_text(
spans,
*,
size=None,
color=None,
font=None,
line_height=None,
width=None,
align_x=None,
wrap=True,
)

Text made of spans with different styles. Plain strings are unstyled spans.

Property Default Description
spans required List of span(...) or strings.
size None Size.
color None Text or icon color.
font None Font of the span or text (family name, e.g. "IBM Plex Mono").
line_height None Line height.
width None Width: pixels, "fill", "shrink" or "fill:N" (proportion).
align_x None Horizontal alignment: "start"/"left", "center", "end"/"right".
wrap True Line wrapping / moves children to a new row when they don’t fit.

Full reference →

span(
text,
*,
color=None,
size=None,
font=None,
weight=None,
italic=False,
bg=None,
radius=0.0,
padding=None,
underline=False,
strikethrough=False,
link=None,
)

A styled span for rich_text. With link, clicking it sends (or calls) that value.

Property Default Description
text required The text.
color None Text or icon color.
size None Size.
font None Font of the span or text (family name, e.g. "IBM Plex Mono").
weight None Font weight: "normal", "medium", "semibold" or "bold".
italic False If True, the span is drawn in italics.
bg None Background color ("#rrggbb[aa]", (r, g, b[, a]) or "transparent").
radius 0.0 Background radius.
padding None Inner padding: 8, (vertical, horizontal) or (top, right, bottom, left).
underline False Underline.
strikethrough False Strikethrough.
link None Message or callable on click.

Full reference →