Skip to content

Commit 0490a4d

Browse files
authored
Merge pull request #5893 from Textualize/containers-howto
Containers howto
2 parents 6e4f77b + ae11740 commit 0490a4d

File tree

12 files changed

+584
-10
lines changed

12 files changed

+584
-10
lines 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") # (1)!
28+
with Center(classes="with-border"): # (2)!
29+
yield Box("Box 2")
30+
with Right(classes="with-border"): # (3)!
31+
yield Box("Box 3")
32+
33+
34+
if __name__ == "__main__":
35+
app = ContainerApp()
36+
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 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 Middle(classes="with-border"): # (1)!
28+
yield Box("Box 1.")
29+
yield Box("Box 2.")
30+
yield Box("Box 3.")
31+
32+
33+
if __name__ == "__main__":
34+
app = ContainerApp()
35+
app.run()

0 commit comments

Comments
 (0)