OptionList¶
Added in version 0.17.0
A widget for showing a vertical list of Rich renderable options.
- Focusable
- Container
Examples¶
Options as simple strings¶
An OptionList can be constructed with a simple collection of string
options:
from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, OptionList
class OptionListApp(App[None]):
CSS_PATH = "option_list.tcss"
def compose(self) -> ComposeResult:
yield Header()
yield OptionList(
"Aerilon",
"Aquaria",
"Canceron",
"Caprica",
"Gemenon",
"Leonis",
"Libran",
"Picon",
"Sagittaron",
"Scorpia",
"Tauron",
"Virgon",
)
yield Footer()
if __name__ == "__main__":
OptionListApp().run()
Options as Option instances¶
For finer control over the options, the Option class can be used; this
allows for setting IDs, setting initial disabled state, etc. The Separator
class can be used to add separator lines between options.
from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, OptionList
from textual.widgets.option_list import Option
class OptionListApp(App[None]):
CSS_PATH = "option_list.tcss"
def compose(self) -> ComposeResult:
yield Header()
yield OptionList(
Option("Aerilon", id="aer"),
Option("Aquaria", id="aqu"),