With Python-textual (package) how do I linearly switch between different 'screens'?
11:19 19 Jul 2023

With textual I'd like to build a simple program which presents me with different options I can choose from using OptionList, but one by one, e.g.

First "screen":

what do you want to buy (Car/Bike)?
+---------+
|   Car   |
| > Bike  |
+---------+

bike

And after I pressed/clicked on "Bike" I'd like to see the second 'screen' (with potentially different widgets):

electric (yes/no)?
+---------+
|   Yes   |
| > No    |
+---------+

No

The following code shows me the first list of options but I have no idea how to proceed:

from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, OptionList, Static
from textual import events, on

class SelectType(Static):
    def compose(self) -> ComposeResult:
        yield OptionList(
            "Car",
            "Bike",
        )

    @on(OptionList.OptionSelected)
    def selected(self, *args):
        return None # What to do here?

class MainProgram(App[None]):
    def compose(self) -> ComposeResult:
        yield Header()
        yield Footer()
        yield SelectType()

MainProgram().run()

What to do now? I crawled the tutorial, guides, examples but it looks like they all show me how to build one set of widgets but I didn't find a way to make a transition between one input screen and another one..

python rich textual python-textual