-
The following code uses from textual.app import App
from textual.widgets import ContentSwitcher, DataTable, Tabs, Tab, Label
DATA = [("anji", 23, "[email protected]", "somewhere"), ("mike", 32, "[email protected]", "elsewhere")]
class MyApp(App):
def __init__(self):
super().__init__()
self.table = DataTable(id="table", show_header=True)
self.table.add_columns(*["name", "age", "email", "addr"])
for row in DATA:
self.table.add_row(*row)
def compose(self):
yield Tabs(Tab("Basic", id="table"), Tab("Advanced", id="label"))
with ContentSwitcher(initial="table"):
yield self.table
yield Label("Here's some advanced stuff", id="label")
def on_tabs_tab_activated(self, event):
self.query_one(ContentSwitcher).current = event.tab.id
if __name__ == "__main__":
app = MyApp()
app.run() |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Thank you for your issue. Give us a little time to review it. PS. You might want to check the FAQ if you haven't done so already. This is an automated reply, generated by FAQtory |
Beta Was this translation helpful? Give feedback.
-
update: I changed my code from using from textual.app import App
from textual.widgets import ContentSwitcher, DataTable, Tabs, Tab, Label, TabbedContent
DATA = [("anji", 23, "[email protected]", "somewhere"), ("mike", 32, "[email protected]", "elsewhere")]
class MyApp(App):
def __init__(self):
super().__init__()
self.table = DataTable(id="table", show_header=True)
self.table.add_columns(*["name", "age", "email", "addr"])
for row in DATA:
self.table.add_row(*row)
def compose(self):
with TabbedContent('Basic', 'Advanced'):
yield self.table
yield Label("Here's some advanced stuff", id="label")
if __name__ == "__main__":
app = MyApp()
app.run() |
Beta Was this translation helpful? Give feedback.
-
In a situation like the from textual.app import App
from textual.widgets import DataTable, Label, TabbedContent
DATA = [("anji", 23, "[email protected]", "somewhere"), ("mike", 32, "[email protected]", "elsewhere")]
class MyApp(App):
CSS = """
DataTable {
height: 1fr;
}
"""
def __init__(self):
super().__init__()
self.table = DataTable(id="table", show_header=True)
self.table.add_columns(*["name", "age", "email", "addr"])
for row in DATA:
self.table.add_row(*row)
def compose(self):
with TabbedContent('Basic', 'Advanced'):
yield self.table
yield Label("Here's some advanced stuff", id="label")
if __name__ == "__main__":
app = MyApp()
app.run() |
Beta Was this translation helpful? Give feedback.
In a situation like the
DataTable
needs a hight; for example: