PasswordField#
Masked text input for password entry with an optional visibility toggle.
Usage#
Basic#
bs.PasswordField(placeholder="Enter password…")
Label and message#
Use label= for a field title and message= for helper text below.
bs.PasswordField(
label="Password",
placeholder="Enter password…",
message="Must be at least 8 characters.",
)
Required#
Set required=True to mark the field visually and prevent empty submission.
bs.PasswordField(label="Password", required=True)
Visibility toggle#
The eye-icon button is shown by default and reveals the password while held.
Disable it with show_visibility_toggle=False.
bs.PasswordField(label="With toggle", value="secret123")
bs.PasswordField(label="No toggle", value="secret123", show_visibility_toggle=False)
Programmatic reveal / hide#
Call reveal() and hide() to control masking in code — useful for a
“show password” checkbox pattern.
field = bs.PasswordField(label="Password", show_visibility_toggle=False)
def _toggle_reveal(e):
if checkbox.value:
field.reveal()
else:
field.hide()
checkbox = bs.Checkbox("Show password", on_change=_toggle_reveal)
Custom mask character#
The default mask is '•'. Supply any single character via mask=.
bs.PasswordField(mask="*")
States#
bs.PasswordField(value="secret123", label="Normal")
bs.PasswordField(value="secret123", label="Read only", read_only=True)
bs.PasswordField(value="secret123", label="Disabled", disabled=True)
Reactive binding#
Bind a Signal[str] with textsignal=. The field and signal stay in
sync automatically — typing updates the signal, setting the signal updates
the field.
password = bs.Signal("")
bs.PasswordField(label="Password", textsignal=password)
password.subscribe(lambda v: validate_strength(v))
Submit on Enter#
field = bs.PasswordField(placeholder="Password…")
field.on_submit(lambda e: attempt_login(field.value))
Validation#
Attach rules with add_validation_rule(). Rules run on the configured
trigger ('blur', 'key', or 'manual').
field = bs.PasswordField(label="Password")
field.add_validation_rule(
"stringLength",
message="Password must be at least 8 characters.",
min=8,
trigger="blur",
)
# Explicit validation check
is_valid = field.validate()
Widget sizing#
All widgets accept self-placement kwargs via **kwargs. The parent
container determines which options apply — stack-based parents use stack
kwargs, grid-based parents use grid kwargs. Unrecognised keys are
silently ignored.
Stack#
Used inside VStack, HStack, App, and other stack containers.
|
Fill direction: |
|
Grow to consume extra space in the parent. |
|
Alignment when the widget does not fill the available slot:
|
|
External spacing in pixels. Accepts an integer (equal on all
sides), a 2-tuple |
|
Horizontal external spacing (left and right). Accepts an integer
or a 2-tuple |
|
Vertical external spacing (top and bottom). Accepts an integer
or a 2-tuple |
Grid#
Used inside a Grid container.
|
Zero-based row and column indices. |
|
Number of rows or columns to span. |
|
Alignment and fill within the grid cell. Any combination of
|
|
External spacing in pixels. Accepts an integer, a 2-tuple
|
|
Horizontal external spacing. Accepts an integer or |
|
Vertical external spacing. Accepts an integer or |
See also#
TextField — plain text input
NumberField — numeric input with optional range constraints
API#
The complete reference for PasswordField lives on the
Widgets API page. At a glance:
A masked text field for password input with an optional visibility toggle. |
Full Example#
1
2with bs.App(title="PasswordField Demo", padding=20, gap=16) as app:
3
4 # Basic
5 bs.Label("Basic", font="heading-sm")
6 bs.PasswordField(placeholder="Enter password…", fill="x")
7
8 # Label, message, required
9 bs.Label("Label, Message, Required", font="heading-sm")
10 bs.PasswordField(
11 label="Password",
12 placeholder="Enter password…",
13 message="Must be at least 8 characters.",
14 required=True,
15 fill="x",
16 )
17
18 # Visibility toggle
19 bs.Label("Visibility Toggle", font="heading-sm")
20 with bs.HStack(gap=8, fill="x", fill_items="x", expand_items=True):
21 bs.PasswordField(label="With toggle", value="secret123")
22 bs.PasswordField(label="No toggle", value="secret123", show_visibility_toggle=False)
23
24 # Custom mask character
25 bs.Label("Custom Mask Character", font="heading-sm")
26 with bs.HStack(gap=8, fill="x", fill_items="x", expand_items=True):
27 bs.PasswordField(value="secret", label="Default (•)")
28 bs.PasswordField(value="secret", label="Asterisk (*)", mask="*")
29
30 # States
31 bs.Label("States", font="heading-sm")
32 with bs.HStack(gap=8, fill="x", fill_items="x", expand_items=True):
33 bs.PasswordField(value="secret123", label="Normal")
34 bs.PasswordField(value="secret123", label="Read only", read_only=True)
35 bs.PasswordField(value="secret123", label="Disabled", disabled=True)
36
37app.run()