Building TUIs with Textual

 


 

At work in 1994

Probably working on a Turbo/Borland Pascal program, in a text-only interface, on a PC running MS-DOS.

I suppose in 1994, it could have been running Windows 3.1, but I don't recall.

 


 

Graphical User Interface (GUI)

The Graphical user interface has largely replaced the earlier text-based UIs.

 


 

GUI - Python - Desktop

  • Standard Library: tkinter
  • wxPython
  • Qt for Python
  • More: Awesome Python - gui-development
  •  


     

    GUI - Python - Web

  • Django
  • Flask
  • Quart (if you want async)
  • Pyramid
  • FastAPI (not just APIs)
  • More: Awesome Python - web-frameworks
  •  


     

    GUI - Python - Web/Desktop

    PgAdmin4 is an example of a web application that can run locally or on a server.

     


     

    Textual

    Talk Python to Me

    Episode #336 - Terminal magic with Rich and Textual

    Episode #380 - 7 lessons from building a modern TUI framework

     


     

    Podcast - Python Bytes

    Python Bytes

    Episode #299 - Will McGugan drops by

     


     

    Podcast - Real Python Podcast

    Real Python Podcast

    Episode #80 - Make Your Python App Interactive With a Text User Interface (TUI)

    Article: Python Community Interview With Will McGugan

     


     

    Will McGugan

    github.com/willmcgugan

     


     

    Will McGugan - Textualize/Rich

    Textualize/rich

     


     

    Textualize/Textual

    textual.textualize.io

     


     

    Textual App Examples

    bloomberg/memray: Memray is a memory profiler for Python

    Textualize/frogmouth: A Markdown browser for your terminal

     


     

    Tutorial

    Tutorial

     


     

    Aspects of Textual

  • Widgets

  • Composition

  • Events

  • Reactivity

  • Class and Id: DOM Queries

  • TCSS: Textual CSS

     


     

    Pomodoro Technique

    Pomodoro Technique

     


     

    Git

    I use git for source code management.

    Some projects are on GitHub. Others are pushed to a local git server.

     


     

    pipx

    I have been using pipx to install Python command-line applications (not libraries).

     


     

    Project tools

  • Hatch - Python project manager (environments, packaging, and more)
  • Ruff - linter and code formatter (integrated with Hatch)
  • pytest - testing framework
  • Just - command runner
  •  


     

    Just

    just a command runner

     


     

    Simon Willison

  • github.com/simonw
  • Post: just-with-django.md
  • Post: Python packages with pyproject.toml and nothing else
  •  


     

    Textual Development Tools

  • Textual Devtools
  • tcss-vscode-extension: VS Code extension that enables syntax highlighting for Textual CSS files.
  • pytest-textual-snapshot: Snapshot testing for Textual applications
  •  


     

    A Toasty Requirement

    It was encouraging to see that Textual has a Toast widget. Unfortunately, Textual's Toast widget only pops up in the terminal. I want a system notification.

  • part of the Kivy project
  •  


     

    Project Setup

  • Directory tree (uses a src layout)
  • pyproject.toml
  •  


     

    Project Dependencies

  • Textual - Textual User Interface framework
  • Click - command-line options
  • platformdirs - common directories on different platforms
  • plyer - system notifications
  • python-dotenv - override default settings during development
  • tomlkit - store configuration as TOML
  •  


     

    Textual - Bindings

    Bindings are declared in the App class.

     


     

    Testing a Textual App

    Textual Guide: Testing

    Snapshot testing for Textual apps: pytest-textual-snapshot

     


     

    Using the App

    Daily Markdown - Written to an Obsidian Daily Notes file.

     


     

    What's Next?

  • Add documentation using Material for MkDocs.

  • Create an alternate AppData class that talks to a web API instead of the file system. That would require a web back-end, perhaps built using FastAPI.

     


     

    That's All

    wmelvin.dev

    You can find more of my ramblings in my "stuff" repo on GitHub.