# Count badge

> A round counter that shows 99+ above its max. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/count-badge/

:::tip[In plain words]
A little round number, like the count of unread messages on an app icon.
:::

A round counter for notifications or problems. Above `max` it shows `99+`.

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

**Code:**

```python
pz.row([
    ui.count_badge(3),
    ui.count_badge(42, tint="success"),
    ui.count_badge(120, tint="error"),
    pz.row([ui.icon_button("bell", on_press), ui.count_badge(7)], spacing=2, align="center"),
], spacing=16, align="center")
```

## When to use

- Next to an icon or tab to show how many unread items or errors there are.
- For text statuses use a [Badge](https://albakore.github.io/pyzed/library/badge/).

## Usage

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

pz.row([
    ui.count_badge(3),
    ui.count_badge(42, tint="success"),
    ui.count_badge(120, tint="error"),
    pz.row([ui.icon_button("bell", on_press), ui.count_badge(7)], spacing=2, align="center"),
], spacing=16, 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.
:::

### Count

Above `max` it shows `max+`.

```python
ui.count_badge(3)
```

```python
ui.count_badge(42)
```

```python
ui.count_badge(120)
```

```python
ui.count_badge(12, max=9)
```

### Tint

```python
ui.count_badge(5, tint="success")
```

```python
ui.count_badge(5, tint="warning")
```

```python
ui.count_badge(5, tint="error")
```

### Next to an icon

```python
pz.row([ui.icon_button("bell", on_press), ui.count_badge(7)], spacing=2, align="center")
```

### States and events

With `show_zero=False` it draws nothing at 0 but keeps its place in the layout.

```python
pz.row([ui.icon_button("bell", on_press), ui.count_badge(0, show_zero=False)], align="center")
```

## Events

Count badge 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

### `ui.count_badge`

```python
count_badge(count, *, tint='accent', max=99, show_zero=True, theme=None)
```

A round counter (notifications, problems…). Shows `99+` above `max`.

| Property | Default | Description |
| --- | --- | --- |
| `count` | *required* | The number. |
| `tint` | `"accent"` | Semantic color: `"accent"`, `"error"`, `"warning"`, `"success"`, `"info"` or a token. |
| `max` | `99` | Maximum before showing `N+`. |
| `show_zero` | `True` | With `False`, a count of 0 draws nothing. |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

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

## Related

- [Badge](https://albakore.github.io/pyzed/library/badge/): A small pill for statuses, versions and counters.
- [Indicator](https://albakore.github.io/pyzed/library/indicator/): A colored dot for status, presence or unsaved changes.
- [Status bar](https://albakore.github.io/pyzed/library/status-bar/): The bottom bar: diagnostics, cursor position, language.
