File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ title : " How do I center a widget in a screen?"
3+ alt_titles :
4+ - " centre a widget"
5+ - " center a control"
6+ - " centre a control"
7+ ---
8+
9+ To center a widget within a container use
10+ [ ` align ` ] ( https://textual.textualize.io/styles/align/ ) . But remember that
11+ ` align ` works on the * children* of a container, it isn't something you use
12+ on the child you want centered.
13+
14+ For example, here's an app that shows a ` Button ` in the middle of a
15+ ` Screen ` :
16+
17+ ``` python
18+ from textual.app import App, ComposeResult
19+ from textual.widgets import Button
20+
21+ class ButtonApp (App ):
22+
23+ CSS = """
24+ Screen {
25+ align: center middle;
26+ }
27+ """
28+
29+ def compose (self ) -> ComposeResult:
30+ yield Button(" PUSH ME!" )
31+
32+ if __name__ == " __main__" :
33+ ButtonApp().run()
34+ ```
You can’t perform that action at this time.
0 commit comments