Skip to content

Commit 0a2710f

Browse files
committed
Containers How-to
1 parent 6e4f77b commit 0a2710f

File tree

12 files changed

+496
-0
lines changed

12 files changed

+496
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
### Unreleased
9+
10+
## Added
11+
12+
- Added `CenterMiddle` container
13+
814
## [3.5.0] - 2025-06-20
915

1016
### Changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import Horizontal
3+
from textual.widgets import Placeholder
4+
5+
6+
class Box(Placeholder):
7+
"""Example widget."""
8+
9+
DEFAULT_CSS = """
10+
Box {
11+
width: 16;
12+
height: 8;
13+
}
14+
"""
15+
16+
17+
class ContainerApp(App):
18+
"""Simple app to play with containers."""
19+
20+
def compose(self) -> ComposeResult:
21+
with Horizontal(): # (1)!
22+
yield Box() # (2)!
23+
yield Box()
24+
yield Box()
25+
26+
27+
if __name__ == "__main__":
28+
app = ContainerApp()
29+
app.run()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import Vertical
3+
from textual.widgets import Placeholder
4+
5+
6+
class Box(Placeholder):
7+
"""Example widget."""
8+
9+
DEFAULT_CSS = """
10+
Box {
11+
width: 16;
12+
height: 8;
13+
}
14+
"""
15+
16+
17+
class ContainerApp(App):
18+
"""Simple app to play with containers."""
19+
20+
def compose(self) -> ComposeResult:
21+
with Vertical(): # (1)!
22+
yield Box()
23+
yield Box()
24+
yield Box()
25+
26+
27+
if __name__ == "__main__":
28+
app = ContainerApp()
29+
app.run()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import Horizontal
3+
from textual.widgets import Placeholder
4+
5+
6+
class Box(Placeholder):
7+
"""Example widget."""
8+
9+
DEFAULT_CSS = """
10+
Box {
11+
width: 16;
12+
height: 8;
13+
}
14+
"""
15+
16+
17+
class ContainerApp(App):
18+
"""Simple app to play with containers."""
19+
20+
CSS = """
21+
.with-border {
22+
border: heavy green;
23+
}
24+
"""
25+
26+
def compose(self) -> ComposeResult:
27+
with Horizontal(classes="with-border"): # (1)!
28+
yield Box()
29+
yield Box()
30+
yield Box()
31+
32+
33+
if __name__ == "__main__":
34+
app = ContainerApp()
35+
app.run()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import Horizontal
3+
from textual.widgets import Placeholder
4+
5+
6+
class Box(Placeholder):
7+
"""Example widget."""
8+
9+
DEFAULT_CSS = """
10+
Box {
11+
width: 16;
12+
height: 8;
13+
}
14+
"""
15+
16+
17+
class ContainerApp(App):
18+
"""Simple app to play with containers."""
19+
20+
CSS = """
21+
.with-border {
22+
border: heavy green;
23+
}
24+
"""
25+
26+
def compose(self) -> ComposeResult:
27+
with Horizontal(classes="with-border"):
28+
yield Box()
29+
yield Box()
30+
yield Box()
31+
with Horizontal(classes="with-border"):
32+
yield Box()
33+
yield Box()
34+
yield Box()
35+
36+
37+
if __name__ == "__main__":
38+
app = ContainerApp()
39+
app.run()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import HorizontalGroup
3+
from textual.widgets import Placeholder
4+
5+
6+
class Box(Placeholder):
7+
"""Example widget."""
8+
9+
DEFAULT_CSS = """
10+
Box {
11+
width: 16;
12+
height: 8;
13+
}
14+
"""
15+
16+
17+
class ContainerApp(App):
18+
"""Simple app to play with containers."""
19+
20+
CSS = """
21+
.with-border {
22+
border: heavy green;
23+
}
24+
"""
25+
26+
def compose(self) -> ComposeResult:
27+
with HorizontalGroup(classes="with-border"):
28+
yield Box()
29+
yield Box()
30+
yield Box()
31+
with HorizontalGroup(classes="with-border"):
32+
yield Box()
33+
yield Box()
34+
yield Box()
35+
36+
37+
if __name__ == "__main__":
38+
app = ContainerApp()
39+
app.run()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import Horizontal
3+
from textual.widgets import Placeholder
4+
5+
6+
class Box(Placeholder):
7+
"""Example widget."""
8+
9+
DEFAULT_CSS = """
10+
Box {
11+
width: 16;
12+
height: 8;
13+
}
14+
"""
15+
16+
17+
class ContainerApp(App):
18+
"""Simple app to play with containers."""
19+
20+
CSS = """
21+
.with-border {
22+
border: heavy green;
23+
}
24+
"""
25+
26+
def compose(self) -> ComposeResult:
27+
with Horizontal(classes="with-border"):
28+
for n in range(10):
29+
yield Box(label=f"Box {n+1}")
30+
31+
32+
if __name__ == "__main__":
33+
app = ContainerApp()
34+
app.run()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import HorizontalScroll
3+
from textual.widgets import Placeholder
4+
5+
6+
class Box(Placeholder):
7+
"""Example widget."""
8+
9+
DEFAULT_CSS = """
10+
Box {
11+
width: 16;
12+
height: 8;
13+
}
14+
"""
15+
16+
17+
class ContainerApp(App):
18+
"""Simple app to play with containers."""
19+
20+
CSS = """
21+
.with-border {
22+
border: heavy green;
23+
}
24+
"""
25+
26+
def compose(self) -> ComposeResult:
27+
with HorizontalScroll(classes="with-border"):
28+
for n in range(10):
29+
yield Box(label=f"Box {n+1}")
30+
31+
32+
if __name__ == "__main__":
33+
app = ContainerApp()
34+
app.run()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import Center, Right
3+
from textual.widgets import Placeholder
4+
5+
6+
class Box(Placeholder):
7+
"""Example widget."""
8+
9+
DEFAULT_CSS = """
10+
Box {
11+
width: 16;
12+
height: 5;
13+
}
14+
"""
15+
16+
17+
class ContainerApp(App):
18+
"""Simple app to play with containers."""
19+
20+
CSS = """
21+
.with-border {
22+
border: heavy green;
23+
}
24+
"""
25+
26+
def compose(self) -> ComposeResult:
27+
yield Box("Box 1")
28+
with Center(classes="with-border"):
29+
yield Box("Box 2")
30+
with Right(classes="with-border"):
31+
yield Box("Box 3")
32+
33+
34+
if __name__ == "__main__":
35+
app = ContainerApp()
36+
app.run()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import HorizontalGroup, Middle
3+
from textual.widgets import Placeholder
4+
5+
6+
class Box(Placeholder):
7+
"""Example widget."""
8+
9+
DEFAULT_CSS = """
10+
Box {
11+
width: 16;
12+
height: 5;
13+
}
14+
"""
15+
16+
17+
class ContainerApp(App):
18+
"""Simple app to play with containers."""
19+
20+
CSS = """
21+
.with-border {
22+
border: heavy green;
23+
}
24+
"""
25+
26+
def compose(self) -> ComposeResult:
27+
with HorizontalGroup():
28+
yield Box("Box 1")
29+
with Middle(classes="with-border"):
30+
yield Box("Box 2")
31+
yield Box("Box 3")
32+
33+
34+
if __name__ == "__main__":
35+
app = ContainerApp()
36+
app.run()

0 commit comments

Comments
 (0)