1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How can I center the Input fields? The method align_horizontal does nothing

Discussão em 'Python' iniciado por Stack, Novembro 24, 2025.

  1. Stack

    Stack Membro Participativo

    Python Textual does not center the input fields. I centered the input fields, but they are displayed left justified. How do I center the input fields?

    from textual.app import App, ComposeResult
    from textual.widgets import Header, Input

    class LoginPage(App):
    AUTO_FOCUS = "Input#user"

    userX = ""
    loginOk = False
    user_widget = Input()
    pass_widget = Input()

    def compose(self) -> ComposeResult:
    yield Header()
    self.user_widget = Input(placeholder="Username",id="user")
    self.pass_widget = Input(placeholder="Password", password=True, id="password")

    self.user_widget.styles.align_horizontal = "center"
    self.user_widget.styles.max_width = 25
    self.pass_widget.styles.max_width = 25
    self.pass_widget.styles.align_horizontal = "center"
    yield self.user_widget
    yield self.pass_widget

    def on_input_submitted(self, event: Input.Submitted) -> None:
    if event.input.id == "user":
    self.userX = event.input.value
    self.pass_widget.focus()
    else:
    pswd = event.input.value

    app = LoginPage()
    if __name__ == "__main__":
    app.run()


    [​IMG]

    Continue reading...

Compartilhe esta Página