# Text

> A piece of text with size, color, font and weight. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/text/

:::tip[In plain words]
Text with any size, color and font you choose.
:::

The base text widget: `size`, `color`, `font`, `weight`, `italic`, `line_height`, alignment and wrapping. In a themed UI prefer [Label](https://albakore.github.io/pyzed/library/label/), which takes its color from the theme.

`pz.text` · Category: [Content](https://albakore.github.io/pyzed/library/#content) · [Full reference →](https://albakore.github.io/pyzed/reference/widgets/#text)

**Code:**

```python
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")
```

## When to use

- For text with explicit styles, or custom fonts loaded with `pz.load_font`.

## Usage

```python
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")
```

## Variants

:::note[About these captures]
Each capture is recorded by pyzed itself, off-screen at 2x, in One Dark or One Light to match this site's theme, and cropped to the component so it shows at its real size. The pointer hovers, presses or types into it; a component that does not react to the pointer cycles through a few themes. With reduced motion you see the first frame. Open **Code** under a capture to see the snippet that draws it; free names such as `on_save` stand for your own callbacks.
:::

### Size

```python
pz.text("Size 12", size=12)
```

```python
pz.text("Size 18", size=18)
```

```python
pz.text("Size 32", size=32)
```

### Font and weight

```python
pz.text("Bold", size=18, weight="bold")
```

```python
pz.text("Light", size=18, weight="light")
```

```python
pz.text("Italic", size=18, italic=True)
```

```python
pz.text("Monospace 0123", size=16, font="mono")
```

### Color and wrapping

```python
pz.text("Golden text", size=18, color="#e5c07b")
```

```python
pz.container(pz.text("A long sentence that wraps over several lines, centered.", align_x="center"),
             width=220)
```

```python
pz.container(pz.text("Taller lines are easier to read in long paragraphs.", line_height=1.8),
             width=220)
```

## Events

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](https://albakore.github.io/pyzed/guides/events/) and [Events of every component](https://albakore.github.io/pyzed/library/events/).

## Properties and API

### `pz.text`

```python
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 →](https://albakore.github.io/pyzed/reference/widgets/#text)

## Related

- [Label](https://albakore.github.io/pyzed/library/label/): Text with a theme color, size and weight; `muted` for secondary text.
- [Rich text](https://albakore.github.io/pyzed/library/rich-text/): One block of text mixing colors, weights and links.
- [Icon](https://albakore.github.io/pyzed/library/icon/): Lucide icons by name, and SVG images.
