TabbedContent (maybe other widgets) do not allow interaction unless composed first #3266
-
Hi, I have searched on opened issues about this but I cannot find anything so there are 2 options: a) I am making a wrong assumption when using the library If it is a) feel free to close 😅 The issueI was debugging my app and found that I cannot create a TabbedContent object and populate it as a I want and later yield it. This should be a quick oversimplified example that would break class TabbedApp(App[None]):
def compose(self) -> ComposeResult:
content = TabbedContent(id="content", initial="tabA")
content.add_pane(TabPane("A", Label("This is tab A", id="tabA")))
content.add_pane(TabPane("B", Label("This is tab B", id="tabB")))
yield content Th reason is that when we add a This creates, what seems to me, an unexpected side effect in which you cannot create your widgets freely and then render them because behaviour of the widget depends on whether they have been already rendered or not. Maybe the intention of the I did what I usually do which is check the tests for the entity in case I can learn how to do it but the only test I find where add_pane is used is done after the compose has been run which would not highlight this issue. This is the test. Am I missing something? Diagnose (in case it is needed)Textual DiagnosticsVersions
Python
Operating System
Terminal
Rich Console options
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Do the examples in the Composing section of the guide to TabbedContents help? https://textual.textualize.io/widgets/tabbed_content/#composing |
Beta Was this translation helpful? Give feedback.
-
You will need to compose the TabbedContent before you call Have you read the docs on composing TabbedContent? If you need to use |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answers! Yes, I went't through the docs and saw the different ways composing it. What I think is misleading is the fact that it is not clear in code or clearly stated in the doc that certain actions require your widget to be composed, or at least I couldn't find it. I think that what I found confusing is that in terms of OOP it seems possible to have a TabbedContent object to which you add a TabPane with the |
Beta Was this translation helpful? Give feedback.
You will need to compose the TabbedContent before you call
add_pane
.Have you read the docs on composing TabbedContent?
If you need to use
add_pane
you could do that inon_mount
. But you shouldn't need it unless its very dynamic.