# Title bar

> The top bar with project and branch pickers. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/title-bar/

:::tip[In plain words]
The bar at the very top of the window, with the project name and quick buttons.
:::

The top bar of the window: widgets at the `start` (project and branch pickers), an optional `center` and widgets at the `end` (account, notifications). `ui.title_button` is the compact button it uses (`pyzed ▾`, `main`), with `chevron` and `muted` styles.

`ui.title_bar` · Category: [Workspace](https://albakore.github.io/pyzed/library/#workspace) · [Full reference →](https://albakore.github.io/pyzed/reference/ui/#title_bar)

**Code:**

```python
ui.title_bar(
    [ui.title_button("pyzed", on_projects, chevron=True),
     ui.title_button("main", on_branches, icon="git-branch", muted=True)],
    [ui.facepile(["Ana", "Luis"]), ui.icon_button("bell", on_bell, size="sm"), ui.avatar("KV")],
    center=ui.muted("notes.py"),
)
```

## When to use

- At the top of a `ui.workspace`, or of any window with `decorations=False`.

## Usage

```python
from pyzed import ui

ui.title_bar(
    [ui.title_button("pyzed", on_projects, chevron=True),
     ui.title_button("main", on_branches, icon="git-branch", muted=True)],
    [ui.facepile(["Ana", "Luis"]), ui.icon_button("bell", on_bell, size="sm"), ui.avatar("KV")],
    center=ui.muted("notes.py"),
)
```

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

### Title buttons

```python
ui.title_button("pyzed", on_projects)
```

```python
ui.title_button("pyzed", on_projects, chevron=True)
```

```python
ui.title_button("main", on_branches, icon="git-branch", muted=True)
```

### Bar

```python
pz.container(ui.title_bar([ui.title_button("pyzed", chevron=True)]), width=420)
```

```python
pz.container(ui.title_bar([], [], center=ui.muted("notes.py — Notes")), width=420)
```

```python
pz.container(ui.title_bar([], [ui.icon_button("bell", on_bell, size="sm"), ui.avatar("KV")]), width=420)
```

## Events

Title bar 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_press` | `()` | Message or callable sent on press. `None` disables the control. |

**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 Ide(pz.App):
    def __init__(self):
        self.picking = None

    def view(self):
        return ui.title_bar([
            ui.title_button("pyzed", lambda: setattr(self, "picking", "project"), chevron=True),
            ui.title_button("main", lambda: setattr(self, "picking", "branch"), icon="git-branch", muted=True),
        ], center=ui.muted(f"Pick a {self.picking}" if self.picking else "notes.py"))
```

**Declarative:**

```python
from dataclasses import dataclass

@dataclass
class Pick:
    what: str

class Ide(pz.App):
    picking = None

    def update(self, message):
        match message:
            case Pick(what):
                self.picking = what

    def view(self):
        return ui.title_bar([ui.title_button("pyzed", Pick("project"), chevron=True),
                             ui.title_button("main", Pick("branch"), icon="git-branch", muted=True)])
```

**Functional:**

```python
from dataclasses import dataclass

@dataclass(frozen=True)
class State:
    project: str = "pyzed"
    projects: tuple = ("pyzed", "notes")

def view(state, set_state):
    nxt = state.projects[(state.projects.index(state.project) + 1) % len(state.projects)]
    return ui.title_bar([ui.title_button(state.project, lambda: set_state(project=nxt), chevron=True)])
```

## Properties and API

### `ui.title_bar`

```python
title_bar(start=(), end=(), *, center=None, height=34, theme=None)
```

The top bar: project and branch pickers on the left, account and actions on the right.

| Property | Default | Description |
| --- | --- | --- |
| `start` | `()` | Widgets at the start (left). |
| `end` | `()` | Widgets at the end (right). |
| `center` | `None` | Centered widget. |
| `height` | `34` | Height. |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

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

### `ui.title_button`

```python
title_button(
    content,
    on_press=None,
    *,
    icon=None,
    muted=False,
    chevron=False,
    theme=None,
)
```

A compact button for the title bar (`pyzed ▾`, `main`…).

| Property | Default | Description |
| --- | --- | --- |
| `content` | *required* | Text. |
| `icon` | `None` | Name of a Lucide icon (`pyzed icons` lists them). |
| `muted` | `False` | Muted text. |
| `chevron` | `False` | Adds a ▾. |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

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

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

## Related

- [Workspace](https://albakore.github.io/pyzed/library/workspace/): The layout of an editor-style window: title bar, docks, center, status bar.
- [Status bar](https://albakore.github.io/pyzed/library/status-bar/): The bottom bar: diagnostics, cursor position, language.
- [Facepile](https://albakore.github.io/pyzed/library/facepile/): Overlapping collaborator avatars with +N.
- [Window frame](https://albakore.github.io/pyzed/library/window-frame/): Your own title bar, window buttons and menus.
