Back to blog
Jun 06, 2024
2 min read

Textual

A Python-based Text UI : simple to use, clear and effective.

Textual is a lovely old-fashioned text UI for Python.

I’ve used it to build simple UIs to display information without needing to worry about browsers, html and CSS : yes, a basic web page and some simple CSS isn’t that hard, but being old-school, the text is familiar and fun.

UI

How it works is a list of widgets that you can import and use in a container …

from textual.app import App, ComposeResult
from textual.containers import Container, Vertical, Horizontal
from textual.widgets import Header, Footer, Input, Label, Sparkline, \
    Log, ListItem, ListView, Pretty

    def compose(self) -> ComposeResult:
        self.log_message("Building ... ")

        yield Input(placeholder="Hello there", id="command")

        yield Header()

        yield Horizontal (
            Container(
                Label("Topology Counts", classes="topology_counts_title headings"),
                Container(
                        self.topology_counts(),
                        classes="topology_counts panel",
                        id="topology_counts_inner"
                    ),
                id="topology_count_container"),
            id="top_row"
        )