# Diff stat

> `+12 −3` with GitHub-style blocks. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/diff-stat/

:::tip[In plain words]
How many lines were added (green) and removed (red) in a change.
:::

Lines added and removed, with a row of green and red blocks, as in the git panel of a code editor.

`ui.diff_stat` · Category: [Data](https://albakore.github.io/pyzed/library/#data) · [Full reference →](https://albakore.github.io/pyzed/reference/ui/#diff_stat)

**Code:**

```python
pz.column([
    pz.row([ui.label("render.rs", mono=True), pz.hspace(), ui.diff_stat(42, 9)], align="center"),
    pz.row([ui.label("app.py", mono=True), pz.hspace(), ui.diff_stat(3, 27)], align="center"),
    pz.row([ui.label("README.md", mono=True), pz.hspace(), ui.diff_stat(12, 0)], align="center"),
], spacing=10, width=320)
```

## When to use

- Next to a file, commit or pull request in a list of changes.

## Usage

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

pz.column([
    pz.row([ui.label("render.rs", mono=True), pz.hspace(), ui.diff_stat(42, 9)], align="center"),
    pz.row([ui.label("app.py", mono=True), pz.hspace(), ui.diff_stat(3, 27)], align="center"),
    pz.row([ui.label("README.md", mono=True), pz.hspace(), ui.diff_stat(12, 0)], align="center"),
], spacing=10, width=320)
```

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

### Options

```python
ui.diff_stat(42, 3)
```

```python
ui.diff_stat(2, 57)
```

```python
ui.diff_stat(12, 0)
```

```python
ui.diff_stat(120, 40, blocks=10)
```

## Events

Diff stat 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.diff_stat`

```python
diff_stat(added, removed, *, blocks=5, theme=None)
```

`+12 −3` with GitHub-style colored blocks.

| Property | Default | Description |
| --- | --- | --- |
| `added` | *required* | Lines added. |
| `removed` | *required* | Lines removed. |
| `blocks` | `5` | Number of blocks. |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

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

## Related

- [Badge](https://albakore.github.io/pyzed/library/badge/): A small pill for statuses, versions and counters.
- [Tree](https://albakore.github.io/pyzed/library/tree/): A collapsible file tree with icons and git colors.
