textual/docs/examples/widgets/select_from_values_widget.py
azinneck0485 87ef1bbcc1
Add Select.from_values class method for initializing with iterator (#3743)
* prototype to use class method to initialize Select object using an iterator

* add docstring and optional arguments to Select.from_values()

* add test widget for Select.from_values() and update documentation to include an example for its use

* add snapshot tests to Select.from_values() class method and update snapshots to include results

* address review comments

---------

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2023-12-05 14:17:25 +00:00

26 lines
652 B
Python

from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Header, Select
LINES = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.""".splitlines()
class SelectApp(App):
CSS_PATH = "select.tcss"
def compose(self) -> ComposeResult:
yield Header()
yield Select.from_values(LINES)
@on(Select.Changed)
def select_changed(self, event: Select.Changed) -> None:
self.title = str(event.value)
if __name__ == "__main__":
app = SelectApp()
app.run()