# QR code

> A QR code for any text or URL. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/qr-code/

:::tip[In plain words]
A square barcode a phone camera can read, for sharing a link.
:::

Draws a QR code that encodes `data`. `cell_size` sets the size of each module; `color` and `bg` change its colors.

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

**Code:**

```python
pz.row([
    pz.qr_code("https://albakore.github.io/pyzed/", cell_size=5),
    pz.qr_code("pyzed", cell_size=5, color="#74ade8", bg="#282c33"),
], spacing=24, align="center")
```

## When to use

- To pass a link, a Wi-Fi password or a pairing code to a phone.

## Usage

```python
import pyzed as pz

pz.row([
    pz.qr_code("https://albakore.github.io/pyzed/", cell_size=5),
    pz.qr_code("pyzed", cell_size=5, color="#74ade8", bg="#282c33"),
], spacing=24, 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.
:::

### Options

```python
pz.qr_code("https://albakore.github.io/pyzed/", cell_size=3)
```

```python
pz.qr_code("pyzed", cell_size=5)
```

```python
pz.qr_code("pyzed", cell_size=5, color="#74ade8", bg="#1e2228")
```

## Events

QR code 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.qr_code`

```python
qr_code(data, *, cell_size=4.0, color=None, bg=None)
```

A QR code that encodes `data`.

| Property | Default | Description |
| --- | --- | --- |
| `data` | *required* | The text or URL to encode. |
| `cell_size` | `4.0` | Size of each module in pixels. |
| `color` | `None` | Text or icon color. |
| `bg` | `None` | Background color (`"#rrggbb[aa]"`, `(r, g, b[, a])` or `"transparent"`). |

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

## Related

- [Image](https://albakore.github.io/pyzed/library/image/): Bitmaps with fit, opacity, radius; a pan-and-zoom viewer.
- [Canvas](https://albakore.github.io/pyzed/library/canvas/): 2D drawing with shapes, paths, text and mouse events.
