Skip to content
Discussion options

You must be logged in to vote

You my find this discussion handy here. Long story short, I'd do it like this:

from textual.app import App, ComposeResult
from textual.widgets import Button, Label
from textual.containers import Horizontal

class CenteredApp(App):
    CSS = """
    Screen {
        align: center middle;
    }

    Horizontal {
        align: center middle;
        height: auto;
    }
    """

    def compose(self) -> ComposeResult:
        yield Horizontal(Label("I would like both this text and the button to be centered"))
        yield Horizontal(Button("PUSH ME!"))


if __name__ == "__main__":
    CenteredApp().run()

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by davep
Comment options

TomJGooding
Mar 1, 2023
Collaborator Author

You must be logged in to vote
2 replies
@davep
Comment options

@TomJGooding
Comment options

TomJGooding Mar 1, 2023
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants