-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_table_get_position.py
34 lines (27 loc) · 1.03 KB
/
data_table_get_position.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from textual.app import App, ComposeResult
from textual.widgets import DataTable, Label
ROWS = [
("lane", "swimmer", "country", "time"),
(4, "Joseph Schooling", "Singapore", 50.39),
(2, "Michael Phelps", "United States", 51.14),
(5, "Chad le Clos", "South Africa", 51.14),
(6, "László Cseh", "Hungary", 51.14),
(3, "Li Zhuhao", "China", 51.26),
(8, "Mehdy Metella", "France", 51.58),
(7, "Tom Shields", "United States", 51.73),
(1, "Aleksandr Sadovnikov", "Russia", 51.84),
(10, "Darren Burns", "Scotland", 51.84),
]
class TableApp(App):
def compose(self) -> ComposeResult:
yield Label()
yield DataTable()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_columns(*ROWS[0])
table.add_rows(ROWS[1:])
def on_data_table_cell_highlighted(self, event: DataTable.CellHighlighted) -> None:
self.query_one(Label).update(f"[bold red]Cell value at cursor: {event.value}")
app = TableApp()
if __name__ == "__main__":
app.run()