Skip to content

Gtk.EditableLabel

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

Allows users to edit the displayed text by switching to an “edit mode”.

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

GtkEditableLabel does not have API of its own, but it implements the Editable interface.

The default bindings for activating the edit mode is to click or press the Enter key. The default bindings for leaving the edit mode are the Enter key (to save the results) or the Escape key (to cancel the editing).

Shortcuts and Gestures

GtkEditableLabel supports the following keyboard shortcuts:

  • <kbd>Enter</kbd> starts editing.
  • <kbd>Escape</kbd> stops editing.

Actions

GtkEditableLabel defines a set of built-in actions:

  • editing.starts switches the widget into editing mode.
  • editing.stop switches the widget out of editing mode.

CSS nodes

editablelabel[.editing]
╰── stack
    ├── label
    ╰── text

GtkEditableLabel has a main node with the name editablelabel. When the entry is in editing mode, it gets the .editing style class.

For all the subnodes added to the text node in various situations, see Text.

Constructors

new

@classmethod
def new(cls, str: str) -> Widget

Creates a new GtkEditableLabel widget.

Parameters:

  • str — the text for the label

Methods

get_editing

def get_editing(self) -> bool

Returns whether the label is currently in “editing mode”.

start_editing

def start_editing(self) -> None

Switches the label into “editing mode”.

stop_editing

def stop_editing(self, commit: bool) -> None

Switches the label out of “editing mode”.

If commit is True, the resulting text is kept as the Editable.text property value, otherwise the resulting text is discarded and the label will keep its previous Editable.text property value.

Parameters:

  • commit — whether to set the edited text on the label

Properties

editing

editing: bool  # read/write

This property is True while the widget is in edit mode.