mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
32 lines
891 B
Python
32 lines
891 B
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")
|
|
|
|
def action_toggle_dark(self) -> None:
|
|
self.app.dark = not self.app.dark
|
|
|
|
|
|
app = TableApp()
|
|
if __name__ == "__main__":
|
|
app.run()
|