Removing a widget initialized w/ argument results in "compose() returned an invalid response; compose() missing 1 required positional argument" #1282
-
I am probably misunderstanding something basic from the stopwatch tutorial, but in trying to create my own "dynamic widgets" example app, I ran into what seems like buggy behavior for calling Maybe I should be passing arguments to a class's
Result:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Glancing at your code, I think the main issue you have here is that you're passing extra arguments to 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) -> ComposeResult:
yield Static(self._text)
class ThingApp(App):
BINDINGS = [
("d", "remove_thing", "Remove Thing")
]
def compose(self) -> ComposeResult:
yield Container(Thing("thing_1"), id="things")
def action_remove_thing(self) -> None:
things = self.query("Thing")
if len(things) > 0:
things.last().remove()
if __name__ == "__main__":
app = ThingApp()
app.run() Now, perhaps your code is going to add more complexity to your from textual.app import App, ComposeResult
from textual.containers import Container
from textual.widgets import Static
class Thing(Static):
pass
class ThingApp(App):
BINDINGS = [
("d", "remove_thing", "Remove Thing")
]
def compose(self) -> ComposeResult:
yield Container(Thing("thing_1"), id="things")
def action_remove_thing(self) -> None:
things = self.query("Thing")
if len(things) > 0:
things.last().remove()
if __name__ == "__main__":
app = ThingApp()
app.run() The change being that your class Thing(Static):
pass |
Beta Was this translation helpful? Give feedback.
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 Pythonclass
you handle construction-based parameters via__init__
. So, to take your example code, it would be more like this: