File: toast.md

package info (click to toggle)
textual 2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 55,056 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (106 lines) | stat: -rw-r--r-- 2,006 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Toast

!!! tip "Added in version 0.30.0"

A widget which displays a notification message.

- [ ] Focusable
- [ ] Container

!!! warning "Note that `Toast` isn't designed to be used directly in your applications, but it is instead used by [`notify`][textual.app.App.notify] to display a message when using Textual's built-in notification system."

## Styling

You can customize the style of Toasts by targeting the `Toast` [CSS type](../guide/CSS.md#type-selector).
For example:

```scss
Toast {
    padding: 3;
}
```

If you wish to change the location of Toasts, it is possible by targeting the `ToastRack` CSS type.
For example:

```scss
ToastRack {
        align: right top;
}
```

The three severity levels also have corresponding
[classes](../guide/CSS.md#class-name-selector), allowing you to target the
different styles of notification. They are:

- `-information`
- `-warning`
- `-error`

If you wish to tailor the notifications for your application you can add
rules to your CSS like this:

```scss
Toast.-information {
    /* Styling here. */
}

Toast.-warning {
    /* Styling here. */
}

Toast.-error {
    /* Styling here. */
}
```

You can customize just the title wih the `toast--title` class.
The following would make the title italic for an information toast:

```scss
Toast.-information .toast--title {
    text-style: italic;
}

```

## Example

=== "Output"

    ```{.textual path="docs/examples/widgets/toast.py"}
    ```

=== "toast.py"

    ```python
    --8<-- "docs/examples/widgets/toast.py"
    ```

## Reactive Attributes

This widget has no reactive attributes.

## Messages

This widget posts no messages.

## Bindings

This widget has no bindings.

## Component Classes

The toast widget provides the following component classes:

::: textual.widgets._toast.Toast.COMPONENT_CLASSES
    options:
      show_root_heading: false
      show_root_toc_entry: false

---

::: textual.widgets._toast.Toast
    options:
      show_root_heading: true
      show_root_toc_entry: true