使用Flet库写的登录界面
需要pip install flet [Python] 纯文本查看 复制代码 import flet as ft
from flet import Page, TextField, Checkbox, \
ElevatedButton, Text, Row, Column, ControlEvent, app
def main(page: Page):
page.title = 'login'
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.theme_mode = ft.ThemeMode.LIGHT
page.window_width = 400
page.window_height = 380
page.window_resizable = False
text_username: TextField = TextField(
label="用户名", text_align=ft.TextAlign.LEFT, width=200)
text_password: TextField = TextField(
label="密码", text_align=ft.TextAlign.LEFT, width=200, password=True)
checkbox_signup: Checkbox = Checkbox(label="我同意下述......", value=False)
button_submit: ElevatedButton = ElevatedButton(
text='登录', width=200, disabled=True)
def validate(e: ControlEvent) -> None:
if all([text_username.value, text_password.value, checkbox_signup.value]):
button_submit.disabled = False
else:
button_submit.disabled = True
page.update()
def submit(e: ControlEvent) -> None:
print('Username', text_username.value)
print('Password', text_password.value)
page.clean()
page.add(
Row(
controls=[Text(value=f'欢迎【{text_username.value}】登录!', size=20)],
alignment=ft.MainAxisAlignment.CENTER
)
)
checkbox_signup.on_change = validate
text_username.on_change = validate
text_password.on_change = validate
button_submit.on_click = submit
page.add(Row(
controls=[
Column(
[
text_username,
text_password,
checkbox_signup,
button_submit
],
)
],
alignment=ft.MainAxisAlignment.CENTER
))
app(target=main)
|