Skip to content

List View

Displays a vertical list of ListItems which can be highlighted and selected. Supports keyboard navigation.

  • Focusable
  • Container

Example

The example below shows an app with a simple ListView.

ListViewExample One Two Three

from textual.app import App, ComposeResult
from textual.widgets import ListView, ListItem, Label, Footer


class ListViewExample(App):

    CSS_PATH = "list_view.css"

    def compose(self) -> ComposeResult:
        yield ListView(
            ListItem(Label("One")),
            ListItem(Label("Two")),
            ListItem(Label("Three")),
        )
        yield Footer()


if __name__ == "__main__":
    app = ListViewExample()
    app.run()
Screen {
    align: center middle;
}

ListView {
    width: 30;
    height: auto;
    margin: 2 2;
}

Label {
    padding: 1 2;
}

Reactive Attributes

Name Type Default Description
index int 0 The currently highlighted index

Messages

Highlighted

The ListView.Highlighted message is emitted when the highlight changes. This happens when you use the arrow keys on your keyboard and when you click on a list item.

  • Bubbles

Attributes

attribute type purpose
item ListItem The item that was highlighted.

Selected

The ListView.Selected message is emitted when a list item is selected. You can select a list item by pressing Enter while it is highlighted, or by clicking on it.

  • Bubbles

Attributes

attribute type purpose
item ListItem The item that was selected.

See Also