-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
There's a couple of different problems with your code. First off, Textual widgets have a A clean starting point for your code would be something like this: from textual.app import App, ComposeResult
from textual.widgets import Static, ListView, ListItem, Header, Footer
class Demo(App[None]):
def compose(self) -> ComposeResult:
yield Header()
yield ListView(ListItem(Static("Text Item", id="nav-1")))
yield Footer()
if __name__ == "__main__":
Demo().run()Assuming you want to add to what you were trying to do, but this was a basic example, a starting point more akin to what you were doing might be this: from textual.app import App, ComposeResult
from textual.widgets import Static, ListView, ListItem, Header, Footer
class Text(Static):
pass
class MenuItem(ListItem):
def __init__(self, text: str, id: str | None = None) -> None:
super().__init__(id=id)
self._text = text
def compose(self) -> ComposeResult:
yield Text(self._text, id=self.id)
class Demo(App[None]):
def compose(self) -> ComposeResult:
yield Header()
yield ListView(MenuItem("Text Item", "nav-1"))
yield Footer()
if __name__ == "__main__":
Demo().run() |
Beta Was this translation helpful? Give feedback.


There's a couple of different problems with your code. First off, Textual widgets have a
nameand anidproperty anyway, so if you're overriding the__init__and you want to use those you'll need to pass them to thesuper().__init__call. Secondly, when you instantiate yourTextwidget, which inherits fromStatic, you're passing more positional arguments thanStatic's__init__is designed to take; it has only the one positional argument, the rest are keyword arguments.A clean starting point for your code would be something like this: