mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from textual.app import App, ComposeResult
|
|
from textual.widgets import DataTable
|
|
|
|
|
|
class TableApp(App):
|
|
def compose(self) -> ComposeResult:
|
|
table = self.table = DataTable(id="data")
|
|
table.add_column("Foo", width=16)
|
|
table.add_column("Bar", width=16)
|
|
table.add_column("Baz", width=16)
|
|
table.add_column("Egg", width=16)
|
|
table.add_column("Foo", width=16)
|
|
table.add_column("Bar", width=16)
|
|
table.add_column("Baz", width=16)
|
|
table.add_column("Egg", width=16)
|
|
|
|
for n in range(100):
|
|
row = [f"row [b]{n}[/b] col [i]{c}[/i]" for c in range(8)]
|
|
table.add_row(*row)
|
|
yield table
|
|
|
|
def on_mount(self):
|
|
self.bind("d", "toggle_dark")
|
|
self.bind("z", "toggle_zebra")
|
|
self.bind("x", "exit")
|
|
|
|
def action_toggle_dark(self) -> None:
|
|
self.app.dark = not self.app.dark
|
|
|
|
def action_toggle_zebra(self) -> None:
|
|
self.table.zebra_stripes = not self.table.zebra_stripes
|
|
|
|
def action_exit(self) -> None:
|
|
from rich.style import Style
|
|
self.exit(Style._add_cache.cache_info())
|
|
|
|
app = TableApp()
|
|
if __name__ == "__main__":
|
|
print(app.run())
|