# Callout

> An inline notice with a title, text and actions. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

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

:::tip[In plain words]
A colored box inside the page with a message: a tip, a warning or an error.
:::

An inline notice (a callout or banner): an icon, a title, an optional description, action buttons and a close button with `on_dismiss`. `tint` is `"info"` (default), `"success"`, `"warning"`, `"error"` or any theme token.

`ui.callout` · Category: [Feedback](https://albakore.github.io/pyzed/library/#feedback) · [Full reference →](https://albakore.github.io/pyzed/reference/ui/#callout)

**Code:**

```python
pz.column([
    ui.callout("A new version is out", "Pyzed 0.4 adds the component designer.", tint="info",
               actions=[ui.button("What's new", on_open, size="sm")], on_dismiss=on_dismiss),
    ui.callout("Could not save", "The file is read-only.", tint="error"),
], spacing=10, width=520)
```

## When to use

- For messages that belong to a place in the UI: a read-only file, a new version, a failed sync.
- For short-lived messages, use a [Toast](https://albakore.github.io/pyzed/library/toast/).

## Usage

```python
import pyzed as pz
from pyzed import ui

pz.column([
    ui.callout("A new version is out", "Pyzed 0.4 adds the component designer.", tint="info",
               actions=[ui.button("What's new", on_open, size="sm")], on_dismiss=on_dismiss),
    ui.callout("Could not save", "The file is read-only.", tint="error"),
], spacing=10, width=520)
```

## 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.
:::

### Tint

Each tint picks a matching icon; `icon=` chooses another.

```python
pz.container(ui.callout("Heads up", "Pyzed 0.5 is out."), width=380)
```

```python
pz.container(ui.callout("Synced", "All changes are saved.", tint="success"), width=380)
```

```python
pz.container(ui.callout("Unsaved changes", "Save before closing.", tint="warning"), width=380)
```

```python
pz.container(ui.callout("Could not save", "The file is read-only.", tint="error"), width=380)
```

```python
pz.container(ui.callout("Tip", "Ctrl+Shift+P opens the palette.", tint="accent", icon="lightbulb"), width=380)
```

### Content

```python
pz.container(ui.callout("Read-only file"), width=380)
```

```python
pz.container(ui.callout("A new version is out", "Restart to update.",
                        actions=[ui.button("Restart", on_restart, size="sm")]), width=380)
```

```python
pz.container(ui.callout("Welcome!", "Open a folder to start.", on_dismiss=on_dismiss), width=380)
```

## Events

Callout has **1 event of its own**, listed below. 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/).

| Event | Handler gets | When |
| --- | --- | --- |
| `on_dismiss` | `()` | Adds a close button. |

**Handler gets** is what Pyzed passes to your callable: `()` means nothing. Any handler can also be a message (a value that is not callable), which goes to `update()`.

### Handling the events

The same events written three ways. **Imperative**: methods of the app change `self`. **Declarative**: the handlers produce messages and one `update()` decides. **Functional**: a pure function draws an immutable state and asks for changes with `set_state(...)`. See [Imperative, declarative and functional](https://albakore.github.io/pyzed/guides/code-styles/).

**Imperative:**

```python
class Updates(pz.App):
    def __init__(self):
        self.visible = True

    def view(self):
        if not self.visible:
            return ui.muted("No news.")
        return ui.callout("A new version is out", "Pyzed adds the component designer.", tint="info",
                          on_dismiss=lambda: setattr(self, "visible", False))   # adds the ✕
```

**Declarative:**

```python
class Updates(pz.App):
    visible = True

    def update(self, message):
        if message == "dismiss":
            self.visible = False

    def view(self):
        return ui.callout("A new version is out", tint="info", on_dismiss="dismiss") if self.visible \
            else ui.muted("No news.")
```

**Functional:**

```python
from dataclasses import dataclass

@dataclass(frozen=True)
class State:
    visible: bool = True

def view(state, set_state):
    if not state.visible:
        return ui.muted("No news.")
    return ui.callout("A new version is out", tint="info", on_dismiss=lambda: set_state(visible=False))
```

## Properties and API

### `ui.callout`

```python
callout(
    title,
    description=None,
    *,
    tint='info',
    icon=None,
    actions=(),
    on_dismiss=None,
    theme=None,
)
```

An inline notice (a callout or banner).

| Property | Default | Description |
| --- | --- | --- |
| `title` | *required* | Title (text or widget). |
| `description` | `None` | Secondary text. |
| `tint` | `"info"` | `"info"`, `"success"`, `"warning"`, `"error"` or `"hint"`: picks the color and icon. |
| `icon` | `None` | Name of a Lucide icon (`pyzed icons` lists them). |
| `actions` | `()` | Extra widgets (usually buttons) shown as actions. |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

Events: `on_dismiss` ([events](#events)).

[Full reference →](https://albakore.github.io/pyzed/reference/ui/#callout)

## Related

- [Toast](https://albakore.github.io/pyzed/library/toast/): Notifications stacked in the bottom-right corner.
- [Alert](https://albakore.github.io/pyzed/library/alert/): A message with one button.
- [Empty state](https://albakore.github.io/pyzed/library/empty-state/): A centered placeholder for empty lists and searches.
