It derives from <GtkWidget>.
A single-line text entry.
<GtkText> is the common implementation of single-line
text editing that is shared between <GtkEntry>,
<GtkPasswordEntry>,
<GtkSpinButton>, and other widgets. In all of
these, a <GtkText> instance is used as the delegate
for the <GtkEditable> implementation.
A large number of key bindings s supported by default. If the entered text is longer than the allocation of the widget, the widget will scroll so that the cursor position is visible.
When using an entry for passwords and other sensitive information, it
can be put into “password mode” using text:set-visibility. In this mode, entered text is
displayed using an “invisible” character. By default, GTK picks the
best invisible character that is available in the current font, but it
can be changed with text:set-invisible-char.
If you want to add icons or progress display in an entry, look at
<GtkEntry>. There are other alternatives for more
specialized use cases, such as
<GtkSearchEntry>.
If you need multi-line editable text, use
<GtkTextView>.
<GtkText> supports the following keyboard shortcuts:
Additionally, the following signals have default keybindings:
text:activate
text:backspace
text:copy-clipboard
text:cut-clipboard
text:delete-from-cursor
text:insert-emoji
text:move-cursor
text:paste-clipboard
text:toggle-overwrite
<GtkText> defines a set of built-in actions:
clipboard.copy copies the contents to the clipboard.
clipboard.cut copies the contents to the clipboard and deletes it
from the widget.
clipboard.paste inserts the contents of the clipboard into the
widget.
menu.popup opens the context menu.
misc.insert-emoji opens the Emoji chooser.
misc.toggle-visibility toggles the
<GtkText>:visibility property.
misc.toggle-direction toggles the text direction.
selection.delete deletes the current selection.
selection.select-all selects all of the widgets content.
text.redo redoes the last change to the contents.
text.undo undoes the last change to the contents.
text.clear removes all content.
text[.read-only] ├── placeholder ├── undershoot.left ├── undershoot.right ├── [selection] ├── [cursor-handle[.top] ├── [cursor-handle.bottom] ├── [block-cursor] ├── [cursor-handle[.top/.bottom][.insertion-cursor]] ╰── [window.popup]
<GtkText> has a main node with the name text.
Depending on the properties of the widget, the .read-only style
class may appear.
When the entry has a selection, it adds a subnode with the name
selection.
When the entry is in overwrite mode, it adds a subnode with the name
block-cursor that determines how the block cursor is drawn.
The CSS node for a context menu is added as a subnode with the name
popup.
The undershoot nodes are used to draw the underflow indication
when content is scrolled out of view. These nodes get the .left
or .right style class added depending on where the indication is
drawn.
When touch is used and touch selection handles are shown, they are using
CSS nodes with name cursor-handle. They get the .top or
.bottom style class depending on where they are shown in relation
to the selection. If there is just a single handle for the text cursor,
it gets the style class .insertion-cursor.
<GtkText> uses the Gtk.AccessibleRole.none
role, which causes it to be skipped for accessibility. This is because
<GtkText> is expected to be used as a delegate for a
<GtkEditable> implementation that will be
represented to accessibility.
Whether to activate the default widget when Enter is pressed.
Its value is a boolean.
Set it with (set! (text:activates-default self) value).
A list of Pango attributes to apply to the text.
This is mainly useful to change the size or weight of the text.
The <PangoAttribute>’s start-index
and end-index must refer to the
<GtkEntryBuffer> text, i.e. without the
preedit string.
Its value is a <PangoAttrList>, or
#f.
Set it with (set! (text:attributes self) value).
The <GtkEntryBuffer> object which stores the
text.
Its value is a <GtkEntryBuffer>, or #f.
Set it with (set! (text:buffer self) value).
Whether to suggest Emoji replacements.
Its value is a boolean.
Set it with (set! (text:enable-emoji-completion self) value).
A menu model whose contents will be appended to the context menu.
Its value is a <GMenuModel>, or #f.
Set it with (set! (text:extra-menu self) value).
Which input method module should be used.
See <GtkIMMulticontext>.
Setting this to a non-NULL value overrides the system-wide input
method. See the settings:gtk-im-module setting.
Its value is a string, or #f.
Set it with (set! (text:im-module self) value).
Additional hints that allow input methods to fine-tune their behaviour.
Its value is a <GtkInputHints> (or, to set it,
a list of its symbols, or one of them).
Set it with (set! (text:input-hints self) value).
The purpose of this text field.
This information can be used by on-screen keyboards and other input methods to adjust their behaviour.
Note that setting the purpose to Gtk.InputPurpose.password or
Gtk.InputPurpose.pin is independent from setting text:visibility.
Its value is a <GtkInputPurpose> (or, to set
it, one of its symbols).
Set it with (set! (text:input-purpose self) value).
The character to used when masking contents (in “password mode”).
Its value is an unsigned 32-bit integer.
Set it with (set! (text:invisible-char self) value).
Whether the invisible char has been set.
Its value is a boolean.
Set it with (set! (text:invisible-char-set self) value).
Maximum number of characters that are allowed.
Zero indicates no limit.
Its value is a 32-bit integer.
Set it with (set! (text:max-length self) value).
If text is overwritten when typing.
Its value is a boolean.
Set it with (set! (text:overwrite-mode self) value).
The text that will be displayed in the <GtkText> when
it is empty and unfocused.
Its value is a string, or #f.
Set it with (set! (text:placeholder-text self) value).
Whether the widget should grow and shrink with the content.
Its value is a boolean.
Set it with (set! (text:propagate-text-width self) value).
Number of pixels scrolled of the screen to the left.
Its value is a 32-bit integer.
It is read only.
Custom tabs for this text widget.
Its value is a <PangoTabArray>, or
#f.
Set it with (set! (text:tabs self) value).
When true, pasted multi-line text is truncated to the first line.
Its value is a boolean.
Set it with (set! (text:truncate-multiline self) value).
If false, the text is masked with the “invisible char”.
Its value is a boolean.
Set it with (set! (text:visibility self) value).
Determines the positions of the strong and weak cursors for a given character position.
The position of each cursor is stored as a zero-width rectangle. The strong cursor location is the location where characters of the directionality equal to the base direction are inserted. The weak cursor location is the location where characters of the directionality opposite to the base direction are inserted.
The rectangle positions are in widget coordinates.
Passed: a <GtkText>.
a text widget
Passed: an unsigned 64-bit integer.
the character position
Passed, filled in, and returned: a
<GrapheneRect>.
location to store the strong cursor position
Passed, filled in, and returned: a
<GrapheneRect>.
location to store the weak cursor position
Returns whether pressing Enter will activate the default widget for the window containing the widget.
See text:set-activates-default.
Passed: a <GtkText>.
a text widget
Returned: a boolean.
true if self will activate the default widget
Gets the attribute list that was set on the text widget.
See text:set-attributes.
Passed: a <GtkText>.
a text widget
Returned: a <PangoAttrList>, or #f.
the attribute list
Get the entry buffer object which holds the text for this widget.
Passed: a <GtkText>.
a text widget
Returned: a <GtkEntryBuffer>.
the entry buffer object
Returns whether Emoji completion is enabled.
Passed: a <GtkText>.
a text widget
Returned: a boolean.
true if Emoji completion is enabled
Gets the extra menu model of the text widget.
See text:set-extra-menu.
Passed: a <GtkText>.
a text widget
Returned: a <GMenuModel>, or #f.
the menu model
Gets the input hints of the text widget.
Passed: a <GtkText>.
a text widget
Returned: a <GtkInputHints>.
the input hints
Gets the input purpose of the text widget.
Passed: a <GtkText>.
a text widget
Returned: a <GtkInputPurpose>.
the input purpose
Retrieves the character displayed when visibility is set to false.
Note that GTK does not compute this value unless it needs it, so the
value returned by this function is not very useful unless it has been
explicitly set with text:set-invisible-char.
Passed: a <GtkText>.
a text widget
Returned: a character.
the current invisible char, or 0, if text does not show invisible text at all
Retrieves the maximum allowed length of the contents.
See text:set-max-length.
This is equivalent to getting self’s
<GtkEntryBuffer> and calling
entry-buffer:get-max-length on
it.
Passed: a <GtkText>.
a text widget
Returned: a 32-bit integer.
the maximum allowed number of characters, or 0 if there is no limit
Gets whether text is overwritten when typing.
Passed: a <GtkText>.
a text widget
Returned: a boolean.
whether text is overwritten when typing
Retrieves the text that will be displayed when the text widget is empty and unfocused
See text:set-placeholder-text.
Passed: a <GtkText>.
a text widget
Returned: a string, or #f.
the placeholder text
Returns whether the text widget will grow and shrink with the content.
Passed: a <GtkText>.
a text widget
Returned: a boolean.
true if self will propagate the text width
Gets the tab stops for the text widget.
See text:set-tabs.
Passed: a <GtkText>.
a text widget
Returned: a <PangoTabArray>, or #f.
the tab stops
Retrieves the length of the contents.
This is equivalent to getting self’s
<GtkEntryBuffer> and calling
entry-buffer:get-length on it.
Passed: a <GtkText>.
a text widget
Returned: an unsigned 16-bit integer.
the length of the contents, in characters
Returns whether pasted text will be truncated to the first line.
Passed: a <GtkText>.
a text widget
Returned: a boolean.
true if self will truncate pasted multi-line text
Retrieves whether the text is visible.
Passed: a <GtkText>.
a text widget
Returned: a boolean.
true if the text is visible
Causes the text widget to have the keyboard focus.
It behaves like widget:grab-focus?,
except that it does not select the contents of self.
You only want to call this on some special entries which the user usually doesn’t want to replace all text in, such as search-as-you-type entries.
Passed: a <GtkText>.
a text widget
Returned: a boolean.
true if focus is now inside self
Creates a new <GtkText>.
Returned: a <GtkWidget>.
the new <GtkText>
Creates a new <GtkText> with the specified buffer.
Passed: a <GtkEntryBuffer>.
the buffer to use
Returned: a <GtkWidget>.
a new <GtkText>
Sets whether pressing Enter will activate the default widget.
This usually means that the dialog containing self will be closed, since the default widget is usually one of the dialog buttons.
Passed: a <GtkText>.
a text widget
Passed: a boolean.
true to activate window’s default widget on Enter keypress
Apply attributes to the contents of the text widget.
Passed: a <GtkText>.
a text widget
Passed, or left out: a <PangoAttrList>, or
#f.
a list of style attributes
Set the entry buffer object which holds the text for this widget.
Passed: a <GtkText>.
a text widget
Passed: a <GtkEntryBuffer>.
an entry buffer object
Sets whether Emoji completion is enabled.
If it is, typing ’:’, followed by a recognized keyword, will pop up a window with suggested Emojis matching the keyword.
Passed: a <GtkText>.
a text widget
Passed: a boolean.
true to enable Emoji completion
Sets a menu model to add to the context menu of the text widget.
Passed: a <GtkText>.
a text widget
Passed, or left out: a <GMenuModel>, or
#f.
a menu model
Sets hints that allow input methods to fine-tune their behaviour.
Passed: a <GtkText>.
a text widget
Passed: a <GtkInputHints>, or a list of its
symbols, or one of them.
input hints
Sets the input purpose of the text widget.
The input purpose can be used by on-screen keyboards and other input methods to adjust their behaviour.
Passed: a <GtkText>.
a text widget
Passed: a <GtkInputPurpose>, or one of its
symbols.
the input purpose
Sets the character to use when in “password mode”.
By default, GTK picks the best invisible char available in the current font. If you set the invisible char to 0, then the user will get no feedback at all; there will be no text on the screen as they type.
Passed: a <GtkText>.
a text widget
Passed: a character.
a Unicode character
Sets the maximum allowed length of the contents.
If the current contents are longer than the given length, they will be truncated to fit.
This is equivalent to getting self’s
<GtkEntryBuffer> and calling
entry-buffer:set-max-length on
it.
Passed: a <GtkText>.
a text widget
Passed: a 32-bit integer.
the maximum length of the text, or 0 for no maximum. (other than the maximum length of entries.) The value passed in will be clamped to the range 0-65536
Sets whether the text is overwritten when typing.
Passed: a <GtkText>.
a text widget
Passed: a boolean.
new value
Sets the text to be displayed when the text widget is empty and unfocused.
This can be used to give a visual hint of the expected contents of the text widget.
Passed: a <GtkText>.
a text widget
Passed, or left out: a string, or #f.
a string to be displayed when self is empty and unfocused
Sets whether the text widget should grow and shrink with the content.
Passed: a <GtkText>.
a text widget
Passed: a boolean.
true to propagate the text width
Sets tab stops for the text widget.
Passed: a <GtkText>.
a text widget
Passed, or left out: a <PangoTabArray>, or
#f.
tab stops
Sets whether pasted text should be truncated to the first line.
Passed: a <GtkText>.
a text widget
Passed: a boolean.
true to truncate multi-line text
Sets whether the contents of the text widget are visible or not.
When visibility is set to false, characters are displayed as the invisible char, and it will also appear that way when the text in the widget is copied to the clipboard.
By default, GTK picks the best invisible character available in the
current font, but it can be changed with text:set-invisible-char.
Note that you probably want to set text:input-purpose to Gtk.InputPurpose.password
or Gtk.InputPurpose.pin to inform input methods about the purpose
of this widget, in addition to setting visibility to false.
Passed: a <GtkText>.
a text widget
Passed: a boolean.
true if the contents of the text widget are displayed as plain text
Unsets the invisible char.
After calling this, the default invisible char is used again.
Passed: a <GtkText>.
a text widget
Connect a handler with (connect object text:activate handler). It
is called as (handler self).
Emitted when the user hits the Enter key.
The default bindings for this signal are all forms of the Enter key.
Passed: a <GtkText>.
Connect a handler with (connect object text:backspace handler).
It is called as (handler self).
Emitted when the user asks for it.
This is a keybinding signal.
The default bindings for this signal are Backspace and Shift+Backspace.
Passed: a <GtkText>.
Connect a handler with (connect object text:copy-clipboard
handler). It is called as (handler self).
Emitted to copy the selection to the clipboard.
This is a keybinding signal.
The default bindings for this signal are Ctrl+c and Ctrl+Insert.
Passed: a <GtkText>.
Connect a handler with (connect object text:cut-clipboard
handler). It is called as (handler self).
Emitted to cut the selection to the clipboard.
This is a keybinding signal.
The default bindings for this signal are Ctrl+x and Shift+Delete.
Passed: a <GtkText>.
Connect a handler with (connect object text:delete-from-cursor
handler). It is called as (handler self type count).
Emitted when the user initiates a text deletion.
This is a keybinding signal.
If the type is Gtk.DeleteType.chars, GTK deletes the
selection if there is one, otherwise it deletes the requested number of
characters.
The default bindings for this signal are Delete for deleting a character and Ctrl+Delete for deleting a word.
Passed: a <GtkText>.
Passed: a <GtkDeleteType>.
the granularity of the deletion
Passed: a 32-bit integer.
the number of type units to delete
Connect a handler with (connect object text:insert-at-cursor
handler). It is called as (handler self string).
Emitted when the user initiates the insertion of a fixed string at the cursor.
This is a keybinding signal.
This signal has no default bindings.
Passed: a <GtkText>.
Passed: a string.
the string to insert
Connect a handler with (connect object text:insert-emoji
handler). It is called as (handler self).
Emitted to present the Emoji chooser.
This is a keybinding signal.
The default bindings for this signal are Ctrl+. and Ctrl+;
Passed: a <GtkText>.
Connect a handler with (connect object text:move-cursor handler).
It is called as (handler self step count extend).
Emitted when the user initiates a cursor movement.
If the cursor is not visible in self, this signal causes the viewport to be moved instead.
This is a keybinding signal.
Applications should not connect to it, but may emit it with
GObject.signal_emit_by_name if they need to control the cursor
programmatically.
The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without it does not. There are too many key combinations to list them all here.
Passed: a <GtkText>.
Passed: a <GtkMovementStep>.
the granularity of the move
Passed: a 32-bit integer.
the number of step units to move
Passed: a boolean.
true if the move should extend the selection
Connect a handler with (connect object text:paste-clipboard
handler). It is called as (handler self).
Emitted to paste the contents of the clipboard.
This is a keybinding signal.
The default bindings for this signal are Ctrl+v and Shift+Insert.
Passed: a <GtkText>.
Connect a handler with (connect object text:preedit-changed
handler). It is called as (handler self preedit).
Emitted when the preedit text changes.
If an input method is used, the typed text will not immediately be committed to the buffer. So if you are interested in the text, connect to this signal.
Passed: a <GtkText>.
Passed: a string.
the current preedit string