Skip to content
Discussion options

You must be logged in to vote

Maybe I should be passing arguments to a class's compose method in some other way?

Glancing at your code, I think the main issue you have here is that you're passing extra arguments to compose at all. From what I can tell you're wanting to create your own widget type that you can pass parameters to. As with any Python class you handle construction-based parameters via __init__. So, to take your example code, it would be more like this:

from textual.app import App, ComposeResult
from textual.containers import Container
from textual.widgets import Static


class Thing(Static):

    def __init__( self, text ) -> None:
        self._text = text
        super().__init__()

    def compose(self

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@randerzander
Comment options

@davep
Comment options

Answer selected by randerzander
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1281 on November 25, 2022 06:51.