Creating a widget without having a parent DOM element that affects layout #2731
-
My dilemma is this. I have a large Here's an example: from textual.app import App, ComposeResult
from textual.containers import Grid
from textual.widget import Widget
from textual.widgets import Static
class Row(Widget):
def compose(self) -> ComposeResult:
yield Static("Column 1")
yield Static("Column 2")
class Demo(App):
CSS = """Grid {
grid-size: 2;
}
"""
def compose(self) -> ComposeResult:
with Grid():
for i in range(9):
yield Row()
Demo().run() See how "Column 1" and "Column 2" are aligned vertically to each other? I want all the "Column 1" to be on the left and all the "Column 2" on the right. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
The problem is, as you say, your from textual.app import App, ComposeResult
from textual.containers import Grid
from textual.widgets import Static
class Demo(App):
CSS = """Grid {
grid-size: 2;
}
"""
def compose(self) -> ComposeResult:
with Grid():
for i in range(9):
yield Static("Column 1")
yield Static("Column 2")
if __name__ == "__main__":
Demo().run() |
Beta Was this translation helpful? Give feedback.
If that's the effect you're after, then I wouldn't use a
Grid
for the main layout. Instead I'd probably go with aVertical
of your own widget, which will handle it's own columnar layout: