Skip to content

how to add and fill a TabPane to an existing TabbedContent #5291

Answered by TomJGooding
nnako asked this question in Q&A
Discussion options

You must be logged in to vote

It looks like you are pretty much there already, unless I've misunderstood your question.

Here's a quick example:

from textual.app import App, ComposeResult
from textual.widgets import Footer, Static, TabbedContent, TabPane


class ExampleApp(App):
    BINDINGS = [
        ("a", "add_panes", "Add panes"),
    ]

    def compose(self) -> ComposeResult:
        yield TabbedContent()
        yield Footer()

    def action_add_panes(self) -> None:
        tabbed_content = self.query_one(TabbedContent)
        for i in range(1, 4):
            tabbed_content.add_pane(
                TabPane(
                    f"Tab{i}",
                    Static(f"Tab{i} content"),
                )
      …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@willmcgugan
Comment options

Answer selected by nnako
Comment options

You must be logged in to vote
1 reply
@willmcgugan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants