Программы на Python
Anonymous
Как центрировать поля ввода? Метод align_horizontal ничего не делает.
Сообщение
Anonymous » 24 ноя 2025, 20:14
Python Textual не центрирует поля ввода. Я центрировал поля ввода, но они отображаются по левому краю.
Как центрировать поля ввода?
Код: Выделить всё
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()
Подробнее здесь:
https://stackoverflow.com/questions/798 ... es-nothing
1764004451
Anonymous
Python Textual не центрирует поля ввода. Я центрировал поля ввода, но они отображаются по левому краю. Как центрировать поля ввода? [code]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() [/code] [img]https://i.sstatic.net/VCyZ8aut.jpg[/img] Подробнее здесь: [url]https://stackoverflow.com/questions/79828223/how-can-i-center-the-input-fields-the-method-align-horizontal-does-nothing[/url]