Skip to content

Text

The base text widget: size, color, font, weight, italic, line_height, alignment and wrapping. In a themed UI prefer Label, which takes its color from the theme.

pz.text · Category: Content · Full reference →

TextText
  • For text with explicit styles, or custom fonts loaded with pz.load_font.
import pyzed as pz
pz.column([
pz.text("Pyzed", size=36, weight="bold", color="#74ade8"),
pz.text("Fast, modern desktop UIs in Python.", size=16, color="#a9afbc"),
pz.text("IBM Plex Mono, italic", font="IBM Plex Mono", italic=True, color="#e5c07b"),
], spacing=6, align="center")
Text: size=12Text: size=12
size=12
Code
pz.text("Size 12", size=12)
Text: size=18Text: size=18
size=18
Code
pz.text("Size 18", size=18)
Text: size=32Text: size=32
size=32
Code
pz.text("Size 32", size=32)
Text: weight="bold"Text: weight="bold"
weight="bold"
Code
pz.text("Bold", size=18, weight="bold")
Text: weight="light"Text: weight="light"
weight="light"
Code
pz.text("Light", size=18, weight="light")
Text: italic=TrueText: italic=True
italic=True
Code
pz.text("Italic", size=18, italic=True)
Text: font="mono"Text: font="mono"
font="mono"
Code
pz.text("Monospace 0123", size=16, font="mono")
Text: color="#e5c07b"Text: color="#e5c07b"
color="#e5c07b"
Code
pz.text("Golden text", size=18, color="#e5c07b")
Text: width=, align_x="center"Text: width=, align_x="center"
width=, align_x="center"
Code
pz.container(pz.text("A long sentence that wraps over several lines, centered.", align_x="center"),
width=220)
Text: line_height=1.8Text: line_height=1.8
line_height=1.8
Code
pz.container(pz.text("Taller lines are easier to read in long paragraphs.", line_height=1.8),
width=220)

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.

text(
content,
*,
size=None,
color=None,
font=None,
weight=None,
italic=False,
line_height=None,
align_x=None,
align_y=None,
width=None,
height=None,
wrap=True,
selectable=None,
selection_color=None,
)

A piece of text.

Property Default Description
content required Content: a Widget, a string or a number (converted to text).
size None Font size.
color None Text or icon color.
font None "sans" (IBM Plex Sans), "mono", "icons", "serif" or the name of a family loaded with load_font.
weight None "thin", "light", "normal", "medium", "semibold", "bold", "black" or a number (100–900).
italic False Italic.
line_height None Line height relative to the size (1.0, 1.5…).
align_x None Horizontal alignment: "start"/"left", "center", "end"/"right".
align_y None Vertical alignment: "start"/"top", "center", "end"/"bottom".
width None Width: pixels, "fill", "shrink" or "fill:N" (proportion).
height None Height: pixels, "fill", "shrink" or "fill:N" (proportion).
wrap True Line wrapping. With False the text doesn’t wrap.
selectable None True lets the mouse select the text (drag, double-click a word, triple-click a block) and Ctrl+C copy it. A string names a selection group: the texts and Markdown of one group form a single selection, in the order they are drawn (the lines of a log, the messages of a chat).
selection_color None Color behind the selected text.

Full reference →