Skip to content

Gtk.PasswordEntry

class — extends Widget, Accessible, Buildable, ConstraintTarget, Editable

A single-line text entry widget for entering passwords and other secrets.

<picture> <source srcset="password-entry-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkPasswordEntry" src="password-entry.png"> </picture>

It does not show its contents in clear text, does not allow to copy it to the clipboard, and it shows a warning when Caps Lock is engaged. If the underlying platform allows it, GtkPasswordEntry will also place the text in a non-pageable memory area, to avoid it being written out to disk by the operating system.

Optionally, it can offer a way to reveal the contents in clear text.

GtkPasswordEntry provides only minimal API and should be used with the Editable API.

CSS Nodes

entry.password
╰── text
    ├── image.caps-lock-indicator

GtkPasswordEntry has a single CSS node with name entry that carries a .passwordstyle class. The text Css node below it has a child with name image and style class .caps-lock-indicator for the Caps Lock icon, and possibly other children.

Accessibility

GtkPasswordEntry uses the AccessibleRole.text_box role.

Constructors

new

@classmethod
def new(cls) -> Widget

Creates a GtkPasswordEntry.

Methods

get_extra_menu

def get_extra_menu(self) -> Gio.MenuModel | None

Gets the menu model set with PasswordEntry.set_extra_menu.

get_show_peek_icon

def get_show_peek_icon(self) -> bool

Returns whether the entry is showing an icon to reveal the contents.

set_extra_menu

def set_extra_menu(self, model: Gio.MenuModel | None = ...) -> None

Sets a menu model to add when constructing the context menu for entry.

Parameters:

  • model — a GMenuModel

set_show_peek_icon

def set_show_peek_icon(self, show_peek_icon: bool) -> None

Sets whether the entry should have a clickable icon to reveal the contents.

Setting this to False also hides the text again.

Parameters:

  • show_peek_icon — whether to show the peek icon

Properties

activates_default

activates_default: bool  # read/write

Whether to activate the default widget when Enter is pressed.

extra_menu

extra_menu: Gio.MenuModel  # read/write

A menu model whose contents will be appended to the context menu.

placeholder_text

placeholder_text: str  # read/write

The text that will be displayed in the GtkPasswordEntry when it is empty and unfocused.

show_peek_icon

show_peek_icon: bool  # read/write

Whether to show an icon for revealing the content.

Signals

activate

def on_activate(self) -> None: ...

Emitted when the entry is activated.

The keybindings for this signal are all forms of the Enter key.