Skip to main content

PasswordBox

A Fluent password box: a text box that hides what is typed, with a button to reveal it.

Example:

fluent.PasswordBox(placeholder="Password", value="secret")
fluent.PasswordBox(
placeholder="PIN", reveal_mode=fluent.PasswordRevealMode.HIDDEN
)
PasswordBox
PasswordBox

Inherits: LayoutControl

Properties

  • autofocus - Whether this password box should be focused on initial display.
  • error_text - An error message shown in red below the box, which also gets a red underline.
  • placeholder - The hint shown while value is empty.
  • prefix - An icon or control shown before the password.
  • read_only - Whether the password can be selected but not changed.
  • reveal_mode - Whether and how the user can see the password.
  • value - The current password.

Events

  • on_blur - Called when this password box loses focus.
  • on_change - Called when the password changes.
  • on_focus - Called when this password box receives focus.
  • on_submit - Called when the user submits the password, for example by pressing Enter.

Methods

  • focus - Requests focus for this password box.

Example​

Fluent PasswordBox​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft


def main(page: ft.Page):
page.title = "Fluent PasswordBox"

def handle_change(e: ft.Event[fluent.PasswordBox]):
length = len(e.control.value)
strength.value = (
"Strength: strong" if length >= 12 else f"Strength: weak ({length}/12)"
)

strength = ft.Text("Strength: weak (0/12)")

page.add(
ft.SafeArea(
content=ft.Column(
width=300,
controls=[
fluent.PasswordBox(
key="password",
placeholder="New password",
reveal_mode=fluent.PasswordRevealMode.PEEK_ALWAYS,
on_change=handle_change,
),
strength,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
password_box
Typing a strong password

Properties​

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this password box should be focused on initial display.

error_textclass-attributeinstance-attribute​

error_text: str | None = None

An error message shown in red below the box, which also gets a red underline.

Set it to tell the user that the value is not valid, and set it to None to hide it.

placeholderclass-attributeinstance-attribute​

placeholder: str | None = None

The hint shown while value is empty.

prefixclass-attributeinstance-attribute​

prefix: IconDataOrControl | None = None

An icon or control shown before the password.

read_onlyclass-attributeinstance-attribute​

read_only: bool = False

Whether the password can be selected but not changed.

reveal_modeclass-attributeinstance-attribute​

Whether and how the user can see the password.

valueclass-attributeinstance-attribute​

value: str = ''

The current password.

Events​

on_blurclass-attributeinstance-attribute​

on_blur: ControlEventHandler[PasswordBox] | None = None

Called when this password box loses focus.

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[PasswordBox] | None = None

Called when the password changes.

The data property of the event handler argument contains the new password.

on_focusclass-attributeinstance-attribute​

on_focus: ControlEventHandler[PasswordBox] | None = None

Called when this password box receives focus.

on_submitclass-attributeinstance-attribute​

on_submit: ControlEventHandler[PasswordBox] | None = None

Called when the user submits the password, for example by pressing Enter.

Methods​

focusasync​

focus()

Requests focus for this password box.