
    
        
        
        
                
        
        
        
                
        
        
        
                
        
        
        
                
        
        
        
            
{"version":"https:\/\/jsonfeed.org\/version\/1","title":"mathspp.com feed","home_page_url":"https:\/\/mathspp.com\/blog\/tags\/textual","feed_url":"https:\/\/mathspp.com\/blog\/tags\/textual.json","description":"Stay up-to-date with the articles on mathematics and programming that get published to mathspp.com.","author":{"name":"Rodrigo Gir\u00e3o Serr\u00e3o"},"items":[{"title":"TIL #079 \u2013 Textual app notifications","date_published":"2023-08-31T00:00:00+02:00","id":"https:\/\/mathspp.com\/blog\/til\/textual-app-notifications","url":"https:\/\/mathspp.com\/blog\/til\/textual-app-notifications","content_html":"<p>Today I learned how to create app notifications in Textual.<\/p>\n\n<h2 id=\"textual-app-notifications\">Textual app notifications<a href=\"#textual-app-notifications\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<figure class=\"image-caption\"><img title=\"Textual app notifications.\" alt=\"Textual application that shows a demo of Textual app notifications with different levels of severity.\" src=\"\/user\/pages\/02.blog\/04.til\/079.textual-app-notifications\/_animation.webp\"><figcaption class=\"\">Textual app notifications.<\/figcaption><\/figure>\n<p><a href=\"https:\/\/github.com\/textualize\/textual\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a> has added support for application notifications for a couple of versions and I haven't had the chance to play around with them, so this tiny blog article shows how to use them.<\/p>\n<div class=\"notices yellow\">\n<p>This article was written for Textual version 0.35.1.\nLater versions of Textual may have (small) differences.<\/p>\n<\/div>\n<p>The video above shows Textual app notifications in action.\nTo create a notification, all you need to do is use the method <code>.notify<\/code> on a Textual app.<\/p>\n<p>I created a small application that posts three different notifications when you press the three buttons.\nNotifications in Textual can have one of three severity levels:<\/p>\n<ol>\n<li>\"information\" \u2013 the default;<\/li>\n<li>\"warning\"; and<\/li>\n<li>\"error\".<\/li>\n<\/ol>\n<p>I paired each severity level with a different button and I also changed the timeout on the \"information\" notification so it lingers around for 10 seconds instead of the default (which I think is 2s, but I'm not sure).<\/p>\n<p>The code for the app above is shown below:<\/p>\n<pre><code class=\"language-py\">from textual import on\nfrom textual.app import App, ComposeResult\nfrom textual.containers import Center, Middle\nfrom textual.widgets import Button\n\nclass NotificationsApp(App[None]):\n    CSS = \"Button { margin: 1; }\"\n\n    def compose(self) -&gt; ComposeResult:\n        with Middle():\n            with Center():\n                yield Button(\"Click me.\", id=\"standard\")\n                yield Button.warning(\"Warning...\", id=\"warning\")\n                yield Button.error(\"Error!\", id=\"error\")\n\n    @on(Button.Pressed, \"#standard\")\n    def standard_notification(self) -&gt; None:\n        self.notify(\"Standard button clicked.\", timeout=10)\n\n    @on(Button.Pressed, \"#warning\")\n    def warning_notification(self) -&gt; None:\n        self.notify(\"Attention, this is a warning.\", severity=\"warning\")\n\n    @on(Button.Pressed, \"#error\")\n    def error_notification(self) -&gt; None:\n        self.notify(\"An error just occurred!\", severity=\"error\")\n\nif __name__ == \"__main__\":\n    NotificationsApp().run()<\/code><\/pre>\n<p>See <a href=\"https:\/\/textual.textualize.io\/api\/app\/#textual.app.App.notify\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">the documentation for the method <code>.notify<\/code><\/a> to learn more!<\/p>","summary":"Today I learned how to create app notifications in Textual.","date_modified":"2025-07-23T16:49:02+02:00","tags":["programming","python","textual"],"image":"\/user\/pages\/02.blog\/04.til\/079.textual-app-notifications\/thumbnail.webp"},{"title":"Textual for beginners","date_published":"2023-07-17T00:00:00+02:00","id":"https:\/\/mathspp.com\/blog\/textual-for-beginners","url":"https:\/\/mathspp.com\/blog\/textual-for-beginners","content_html":"<p>This tutorial will introduce beginners to the many features that Textual offers to build elegant and lightweight TUIs.<\/p>\n\n<figure class=\"image-caption\"><img title=\"A TODO app in Textual.\" alt=\"Two screenshots of a TODO app built with Textual, which is the end result you get if you follow along this Textual tutorial for beginners.\" src=\"\/user\/pages\/02.blog\/textual-for-beginners\/_shots.webp\"><figcaption class=\"\">A TODO app in Textual.<\/figcaption><\/figure><h2 id=\"introduction\">Introduction<a href=\"#introduction\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>This tutorial will teach you the basics that you need to use <a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a> to build terminal user interfaces (TUIs).<\/p>\n<p>This is an unofficial written version of <a href=\"https:\/\/ep2023.europython.eu\/session\/build-a-terminal-todo-app-with-textual\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">a tutorial I gave at EuroPython 2023 in Prague<\/a>.<\/p>\n<p>In case you don't know what Textual is, go ahead and read the description below.\nOtherwise, let's get building!<\/p>\n<h3 id=\"what-is-textual\">What is Textual?<a href=\"#what-is-textual\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h3>\n<p><a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a> is a Python framework that lets users build applications that run directly in the terminal.\nQuoting the <a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a> documentation, some of the advantages of using Textual to build applications include:<\/p>\n<ul><li>Rapid development: you can use your existing Python skills to build a beautiful user interface.\nYou don't need to learn new languages to write user interfaces.<\/li>\n<li>Low requirements: you can run Textual on a single board computer if you want to.<\/li>\n<li>Cross-platform: Textual runs just about everywhere you can run Python.<\/li>\n<li>Remote: Textual apps can run over SSH.<\/li>\n<li>CLI integration: Textual apps can be launched and run from the command prompt.<\/li>\n<li>Open source: Textual is licensed under MIT.<\/li>\n<\/ul><h2 id=\"setup\">Setup<a href=\"#setup\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>To get ready for this tutorial, create a new folder, create a new virtual environment, and install Textual!<\/p>\n<pre><code class=\"language-bash\">~:$ mkdir textual-tutorial\n~:$ cd textual-tutorial\n\n~\/textual-tutorial:$ python -m venv .venv\n~\/textual-tutorial:$ . .venv\/bin\/activate\n\n~\/textual-tutorial:$ python -m pip install textual<\/code><\/pre>\n<p>To verify that the installation was successful, run the command<\/p>\n<pre><code class=\"language-bash\">~\/textual-tutorial:$ python -m textual<\/code><\/pre>\n<p>That should open the Textual demo app.\nIt should look something like this:<\/p>\n<figure class=\"image-caption\"><img title=\"Textual demo app.\" alt=\"The Textual demo terminal application that you can run with the command `python -m textual` to verify Textual is working correctly.\" src=\"\/user\/pages\/02.blog\/textual-for-beginners\/_textual_demo.webp\"><figcaption class=\"\">Textual demo app.<\/figcaption><\/figure><p>To quit the app, press <kbd>Ctrl<\/kbd> + <kbd>C<\/kbd>.<\/p>\n<div class=\"notices yellow\">\n<p>This tutorial was written for Textual 0.29.0.\nSome information in this tutorial may become outdated.\nCheck the <a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual docs<\/a> for updated information and <a href=\"https:\/\/discord.gg\/Enf6Z3qhVr\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">join the Textual Discord<\/a> to talk to us.<\/p>\n<\/div>\n<h2 id=\"your-first-textual-app\">Your first Textual app<a href=\"#your-first-textual-app\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>Textual lets you build TUIs &ndash; terminal user interfaces.\nThese are programs that provide an interface for the user to interact with, but they run inside the terminal.<\/p>\n<p>In Textual, the program that shows things to the user and with which the user interacts is called an <em>app<\/em>.\nLet us see how to build your first, most basic app.<\/p>\n<p>An application, in Textual, is a class that inherits from <code>textual.app.App<\/code>.\nThen, to <em>run<\/em> your app, you need to instantiate it and call its method <code>run<\/code>:<\/p>\n<pre><code class=\"language-py\">from textual.app import App\n\nclass MyApp(App):\n    pass\n\nMyApp().run()<\/code><\/pre>\n<p>Run your app with the command:<\/p>\n<pre><code class=\"language-bash\">~:$ python your_first_app.py<\/code><\/pre>\n<p>It should show a black screen, which means your app is running!\nIt does <em>nothing<\/em>, but it is running!\nTo exit your app, press <kbd>Ctrl<\/kbd> + <kbd>C<\/kbd>.<\/p>\n<h2 id=\"showing-widgets-on-the-screen\">Showing widgets on the screen<a href=\"#showing-widgets-on-the-screen\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>For your app to do something useful, you will want to add <em>widgets<\/em> to it.\nWidgets are the interface elements that the user interacts with and that you can use to convey information to the user.<\/p>\n<p>Textual has an <a href=\"https:\/\/textual.textualize.io\/widget_gallery\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">extensive widget library<\/a> that includes:<\/p>\n<ul><li>app headers and footers;<\/li>\n<li>labels;<\/li>\n<li>buttons;<\/li>\n<li>inputs;<\/li>\n<li>radio buttons and checkboxes;<\/li>\n<li>switches;<\/li>\n<li>tabs;...<\/li><\/ul>","summary":"This tutorial will introduce beginners to the many features that Textual offers to build elegant and lightweight TUIs.","date_modified":"2025-07-23T16:49:02+02:00","tags":["programming","python","textual"],"image":"\/user\/pages\/02.blog\/textual-for-beginners\/thumbnail.webp"},{"title":"TIL #067 \u2013 VS Code extension for custom syntax highlighting","date_published":"2023-07-06T00:00:00+02:00","id":"https:\/\/mathspp.com\/blog\/til\/vscode-extension-for-custom-syntax-highlighting","url":"https:\/\/mathspp.com\/blog\/til\/vscode-extension-for-custom-syntax-highlighting","content_html":"<p>Today I learned how to create a VS Code extension to do custom syntax highlighting.<\/p>\n\n<h2 id=\"textual-css\">Textual CSS<a href=\"#textual-css\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>At my day job, developing <a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a>, I have been <a href=\"https:\/\/github.com\/Textualize\/textual\/issues\/2888\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">tasked with writing a VS Code extension that does proper syntax colouring of Textual CSS<\/a>.<\/p>\n<p>That's because Textual CSS looks a lot like regular CSS but the syntax highlighting of regular CSS doesn't look great.\nFor example, most editors will highlight the code below in an uneven way:<\/p>\n<pre><code class=\"language-css\">ModalScreen, #input, .some-class {\n    border: heavy white;\n    tint: $primary 30%;\n}<\/code><\/pre>\n<p>(Try copying &amp; pasting into your code editor of choice.)<\/p>\n<p>For example, the selectors <code>#input<\/code> and <code>.some-class<\/code> are highlighted but the selector <code>ModalScreen<\/code> isn't.\nFurthermore, Textual CSS has rules that regular CSS doesn't, and that is why <code>border<\/code> is a different colour than <code>tint<\/code>.<\/p>\n<h2 id=\"writing-a-vs-code-extension\">Writing a VS Code extension<a href=\"#writing-a-vs-code-extension\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>After getting started with VS Code's guide on <a href=\"https:\/\/code.visualstudio.com\/api\/get-started\/your-first-extension\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">writing your first extension<\/a>, I found <a href=\"https:\/\/code.visualstudio.com\/api\/language-extensions\/syntax-highlight-guide\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">a guide specific to creating extensions that do custom syntax highlighting<\/a>.<\/p>\n<p>A few rabbit holes later and I had an extension that does syntax highlighting of the words \"textual\" and \"Textual\" in <code>.tcss<\/code> files.<\/p>\n<p>\"All\" I needed to do was create a new extension template with <code>yo code<\/code> (as the first guide teaches).<\/p>\n<p>Then, I went to the extension manifest file <code>package.json<\/code> and modified the <code>\"contributes\"<\/code> key:<\/p>\n<pre><code class=\"language-json\">{\n  \"contributes\": {\n    \"languages\": [\n      {\n        \"id\": \"Textual CSS\",\n        \"extensions\": [\".tcss\"]\n      }\n    ],\n    \"grammars\": [\n      {\n        \"language\": \"Textual CSS\",\n        \"scopeName\": \"source.tcss\",\n        \"path\": \".\/syntaxes\/tcss.tmGrammar.json\"\n      }\n    ]\n  }\n}<\/code><\/pre>\n<p>First, we need to \"contribute\" a language, which is Textual CSS, and that corresponds to the language that we want to target with our extension.<\/p>\n<p>Then, we contribute a grammar, which is the TextMate grammar file that specifies how tokens get parsed.\nToken names and scopes are still a bit confusing to me, but after reading <a href=\"https:\/\/www.apeth.com\/nonblog\/stories\/textmatebundle.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">an article that is linked to by the VS Code guide<\/a>, I seem to understand that we prefix the scope name with <code>source<\/code> so that we create a nested scope inside <code>source<\/code>.<\/p>\n<p>In other words, the scope <code>source<\/code> is already a scope that VS Code knows about and we are saying that our Textual CSS files not only contain source code (scoped as <code>source<\/code>), but that they contain a more specific type of source code.\nThis nesting is achieved with the <code>.tcss<\/code>.<\/p>\n<p>Finally, we need to create the actual grammar file.\nThe file <code>tcss.tmGrammar.json<\/code> currently looks like this:<\/p>\n<pre><code class=\"language-json\">{\n    \"scopeName\": \"source.tcss\",\n    \"patterns\": [{\"include\": \"#textual\"}],\n    \"repository\": {\n        \"textual\": {\n            \"match\": \"(T|t)extual\",\n            \"name\": \"keyword\"\n        }\n    }\n}<\/code><\/pre>\n<p>The value that you attribute to <code>\"name\"<\/code> inside <code>\"textual\"<\/code> inside <code>\"repository\"<\/code> is what classifies the words \"textual\" and \"Textual\" as a meaningful token.\nIn this example, I randomly chose <code>keyword<\/code>.\nThen, it is up to the theme that you use to specify what is the colour that <code>keyword<\/code> tokens use.<\/p>\n<p>In the screenshot below, you can see a couple of lines of text with some random highlighting:<\/p>\n<p><img alt=\"A screenshot of some source code with custom highlighting provided by a custom VS Code extension that will eventually do custom syntax highlighting of Textual CSS.\" src=\"\/user\/pages\/02.blog\/04.til\/067.vscode-extension-for-custom-syntax-highlighting\/_textual_highlighted.webp\"><\/p>\n<p>That's it for now! <a href=\"\/subscribe\">Stay tuned<\/a> and I'll see you...<\/p>","summary":"Today I learned how to create a VS Code extension to do custom syntax highlighting.","date_modified":"2025-07-23T16:49:02+02:00","tags":["textual","vscode"],"image":"\/user\/pages\/02.blog\/04.til\/067.vscode-extension-for-custom-syntax-highlighting\/thumbnail.webp"},{"title":"How to use modal screens in Textual","date_published":"2023-05-10T00:00:00+02:00","id":"https:\/\/mathspp.com\/blog\/how-to-use-modal-screens-in-textual","url":"https:\/\/mathspp.com\/blog\/how-to-use-modal-screens-in-textual","content_html":"<p>This is a short tutorial on how to use modal screens with Textual.<\/p>\n\n<div class=\"notices yellow\">\n<p>This tutorial was written with\/for <a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a> 0.24.1.<\/p>\n<\/div>\n<h2 id=\"introduction\">Introduction<a href=\"#introduction\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>This short tutorial will teach you how to use modal screens in <a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a>.<\/p>\n<p>A modal screen is a screen that is typically used for a quick interaction with the user before going back to the main application.<\/p>\n<p>As a quick example, here is <a href=\"\/blog\/textual-tutorial-build-a-todo-app-in-python\">my TODO app<\/a> showing a modal to confirm exiting the app:<\/p>\n<p><img src=\"\/blog\/how-to-use-modal-screens-in-textual\/.\/_todo_with_modal.webp\" alt=\"\"><\/p>\n<h2 id=\"building-a-modal-screen\">Building a modal screen<a href=\"#building-a-modal-screen\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<h3 id=\"inheriting-from-modalscreen\">Inheriting from <code>ModalScreen<\/code>\n<a href=\"#inheriting-from-modalscreen\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h3>\n<p>The first modal screen we will build is the exit screen from the demo above.\nA modal screen needs to inherit from <code>ModalScreen<\/code>, so that is the first thing we need to do:<\/p>\n<pre><code class=\"language-py\">from textual.screen import ModalScreen\n\nclass ExitScreen(ModalScreen):\n    \"\"\"A modal exit screen.\"\"\"<\/code><\/pre>\n<h3 id=\"composing-the-screen\">Composing the screen<a href=\"#composing-the-screen\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h3>\n<p>Next, we need to compose the children widgets that we will need in this screen.\nWe need a label and two buttons, so let us yield them:<\/p>\n<pre><code class=\"language-py\">from textual.app import ComposeResult\nfrom textual.screen import ModalScreen\nfrom textual.widgets import Button, Label\n\nclass ExitScreen(ModalScreen):\n    \"\"\"A modal exit screen.\"\"\"\n\n    def compose(self) -&gt; ComposeResult:\n        yield Label(\"Are you sure you want to quit?\")\n        yield Button(\"no\")\n        yield Button(\"yes\")<\/code><\/pre>\n<p>Now, in order to be able to see this modal screen, we can whip up a dummy app whose only job is to open this modal screen:<\/p>\n<pre><code class=\"language-py\">from textual.app import App, ComposeResult\n\n...\n\nclass DummyApp(App[None]):\n    def compose(self) -&gt; ComposeResult:\n        yield Button(\"Open modal.\")\n\n    def on_button_pressed(self) -&gt; None:\n        self.push_screen(ExitScreen())\n\napp = DummyApp()\nif __name__ == \"__main__\":\n    app.run()<\/code><\/pre>\n<p>This already runs, although it doesn't do much:<\/p>\n<p><img src=\"\/blog\/how-to-use-modal-screens-in-textual\/.\/_modal_demo_1.webp\" alt=\"\"><\/p>\n<h3 id=\"wiring-up-the-modal\">Wiring up the modal<a href=\"#wiring-up-the-modal\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h3>\n<p>A modal screen is just like a regular screen in terms of its functioning, so we can wire the buttons in the usual way:<\/p>\n<ul><li>we will change their variants (to add some styling);<\/li>\n<li>we will add an ID to each button to be able to distinguish which button was pressed; and<\/li>\n<li>we will act accordingly to the button pressed:\n<ul><li>if the button pressed was &ldquo;Yes&rdquo;, we exit the app; and<\/li>\n<li>if the button pressed was &ldquo;No&rdquo;, we go back to the app.<\/li>\n<\/ul><\/li>\n<\/ul><p>First, we change the buttons:<\/p>\n<pre><code class=\"language-py\">...\n\nclass ExitScreen(ModalScreen):\n    \"\"\"A modal exit screen.\"\"\"\n\n    def compose(self) -&gt; ComposeResult:\n        yield Label(\"Are you sure you want to quit?\")\n        yield Button(\"No\", id=\"yes\", variant=\"error\")\n        yield Button(\"Yes\", id=\"no\", variant=\"success\")\n\n...<\/code><\/pre>\n<p>Now, we can add handlers for each button press.\nUsing the new <a href=\"https:\/\/textual.textualize.io\/guide\/events\/#on-decorator\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\"><code>@on<\/code> decorator<\/a>, this is straightforward:<\/p>\n<pre><code class=\"language-py\">from textual import on\n...\n\nclass ExitScreen(ModalScreen):\n    ...\n\n    @on(Button.Pressed, \"#yes\")\n    def exit_app(self) -&gt; None:\n        self.app.exit()\n\n    @on(Button.Pressed, \"#no\")\n    def back_to_app(self) -&gt; None:\n        self.app.pop_screen()\n\n...<\/code><\/pre>\n<p>Now, our modal screen works <em>although<\/em> it does <em>not<\/em> look like a modal screen:<\/p>\n<p><img src=\"\/blog\/how-to-use-modal-screens-in-textual\/.\/_modal_demo_2.webp\" alt=\"\"><\/p>\n<p>We will style the screen next.<\/p>\n<h3 id=\"styling-the-modal-screen\">Styling the modal screen<a href=\"#styling-the-modal-screen\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h3>\n<h4 id=\"make-it-look-like-a-modal\">Make it look like a modal<a href=\"#make-it-look-like-a-modal\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h4>\n<p>The first thing we will do is make the modal screen <em>look<\/em> like a modal screen.\nTo do this, we will wrap all the children of the modal screen in a container so that we can align them in the middle of the modal screen.<\/p>\n<p>By making the container have auto dimensions, we will leave...<\/p>","summary":"This is a short tutorial on how to use modal screens with Textual.","date_modified":"2025-07-23T16:49:02+02:00","tags":["programming","python","textual"],"image":"\/user\/pages\/02.blog\/textual-how-to-use-modal-screens\/thumbnail.png"},{"title":"Textual tutorial \u2013 build a TODO app in Python","date_published":"2023-03-16T00:00:00+01:00","id":"https:\/\/mathspp.com\/blog\/textual-tutorial-build-a-todo-app-in-python","url":"https:\/\/mathspp.com\/blog\/textual-tutorial-build-a-todo-app-in-python","content_html":"<p>Learn how to build a simple TODO app in Python with this step-by-step Textual tutorial.<\/p>\n\n<h2 id=\"introduction\">Introduction<a href=\"#introduction\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>In this tutorial, I will show you to build a TODO app with <a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a>, a Python framework for terminal user interfaces.\nThe TODO app will look like this:<\/p>\n<figure class=\"image-caption\"><img title=\"App demo GIF.\" alt=\"\" src=\"\/user\/pages\/02.blog\/textual-tutorial-build-a-todo-app-in-python\/_app_demo.gif?decoding=auto&amp;fetchpriority=auto\"><figcaption class=\"\">App demo GIF.<\/figcaption><\/figure><p>This tutorial was based on <a href=\"https:\/\/github.com\/Textualize\/textual\/pull\/1818\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">a PR I made for the Textual documentation<\/a>, which was eventually was closed and not merged.\nInstead of letting all my work go to waste, I revised the contents of the PR and I am sharing it here with you.<\/p>\n<p>In case you don't know what Textual is, go ahead and read the description below.\nOtherwise, let's get building!<\/p>\n<h3 id=\"what-is-textual\">What is Textual?<a href=\"#what-is-textual\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h3>\n<p><a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a> is a Python framework that lets users build applications that run directly in the terminal.\nQuoting the <a href=\"https:\/\/textual.textualize.io\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual<\/a> website, some of the advantages of using Textual to build applications include:<\/p>\n<ul><li>Rapid development: you can use your existing Python skills to build a beautiful user interface.\nYou don't need to learn new languages to write user interfaces.<\/li>\n<li>Low requirements: you can run Textual on a single board computer if you want to.<\/li>\n<li>Cross-platform: Textual runs just about everywhere you can run Python.<\/li>\n<li>Remote: Textual apps can run over SSH.<\/li>\n<li>CLI integration: Textual apps can be launched and run from the command prompt.<\/li>\n<li>Open source: Textual is licensed under MIT.<\/li>\n<\/ul><h3 id=\"get-the-code\">Get the code<a href=\"#get-the-code\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h3>\n<p>The code for this app can be found in the <a href=\"https:\/\/github.com\/mathspp\/textual-todo\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">textual-todo GitHub repository<\/a>.\nFeel free to star the repository and fork it to play around with the code.<\/p>\n<p>You can also just install the app with <code>python -m pip install textual-todo<\/code> and run it with <code>todo<\/code>!<\/p>\n<h3 id=\"getting-up-to-speed\">Getting up to speed<a href=\"#getting-up-to-speed\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h3>\n<p>This tutorial assumes you already know the <em>essentials<\/em> about Textual.\nIf you are a complete newcomer to Textual, I recommend you take a look at the <a href=\"https:\/\/textual.textualize.io\/tutorial\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">Textual tutorial<\/a> before diving into this article.\nThe Textual tutorial should teach you everything you need to follow along with this one! &#128521;<\/p>\n<h2 id=\"todo-app-architecture\">TODO app architecture<a href=\"#todo-app-architecture\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>Our TODO app will have the following features:<\/p>\n<ul><li>add arbitrarily many new TODO items;<\/li>\n<li>set and edit a description of the TODO item;<\/li>\n<li>set and edit the due date for each item;<\/li>\n<li>items colour-coded by whether the item is late, on time, or only due in the future;<\/li>\n<li>items are sorted automatically by due date;<\/li>\n<li>long item descriptions are collapsible;<\/li>\n<li>mark items as done; and<\/li>\n<li>persistence of TODO items across runs.<\/li>\n<\/ul><p>The starting point for this application is going to be a custom compound widget.\nA compound widget is a custom widget that is implemented by combining multiple other widgets.<\/p>\n<p>We will start by building an editable text widget that shows some text and then contains two buttons:\none lets us edit the text and the other confirms the changes we made to the text.\nWe will use this simpler compound widget to illustrate the points made above.<\/p>\n<p>Then, we will subclass that widget to create a more specialised editable text widget that is specifically used for dates....<\/p>","summary":"Learn how to build a simple TODO app in Python with this step-by-step Textual tutorial.","date_modified":"2025-07-23T16:49:02+02:00","tags":["programming","python","textual"],"image":"\/user\/pages\/02.blog\/textual-tutorial-build-a-todo-app-in-python\/thumbnail.webp"}]}
