gtk.text
Module for [Text] class
Types 3
The [gtk.text.Text] widget is a single-line text entry widget.
[gtk.text.Text] is the common implementation of single-line text editing that is shared between [gtk.entry.Entry], [gtk.password_entry.PasswordEntry], [gtk.spin_button.SpinButton], and other widgets. In all of these, [gtk.text.Text] is used as the delegate for the [gtk.editable.Editable] implementation.
A fairly large set of key bindings are 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 [gtk.text.Text.setVisibility]. In this mode, entered text is displayed using a “invisible” character. By default, GTK picks the best invisible character that is available in the current font, but it can be changed with [gtk.text.Text.setInvisibleChar].
If you are looking to add icons or progress display in an entry, look at [gtk.entry.Entry]. There other alternatives for more specialized use cases, such as [gtk.search_entry.SearchEntry].
If you need multi-line editable text, look at [gtk.text_view.TextView].
CSS nodes
text[.read-only]
├── placeholder
├── undershoot.left
├── undershoot.right
├── [selection]
├── [block-cursor]
╰── [window.popup][gtk.text.Text] 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.
Accessibility
[gtk.text.Text] uses the [gtk.types.AccessibleRole.None] role, which causes it to be skipped for accessibility. This is because [gtk.text.Text] is expected to be used as a delegate for a [gtk.editable.Editable] implementation that will be represented to accessibility.
Text self()Returns `this`, for use in `with` statements.TextGidBuilder builder()Get builder for [gtk.text.Text] Returns: New builder objectbool activatesDefault() @propertyGet `activatesDefault` property. Returns: Whether to activate the default widget when Enter is pressed.void activatesDefault(bool propval) @propertySet `activatesDefault` property. Params: propval = Whether to activate the default widget when Enter is pressed.pango.attr_list.AttrList attributes() @propertyGet `attributes` property. Returns: A list of Pango attributes to apply to the text of the [gtk.text.Text].void attributes(pango.attr_list.AttrList propval) @propertySet `attributes` property. Params: propval = A list of Pango attributes to apply to the text of the [gtk.text.Text].gtk.entry_buffer.EntryBuffer buffer() @propertyGet `buffer` property. Returns: The [gtk.entry_buffer.EntryBuffer] object which stores the text.void buffer(gtk.entry_buffer.EntryBuffer propval) @propertySet `buffer` property. Params: propval = The [gtk.entry_buffer.EntryBuffer] object which stores the text.bool enableEmojiCompletion() @propertyGet `enableEmojiCompletion` property. Returns: Whether to suggest Emoji replacements.void enableEmojiCompletion(bool propval) @propertySet `enableEmojiCompletion` property. Params: propval = Whether to suggest Emoji replacements.gio.menu_model.MenuModel extraMenu() @propertyGet `extraMenu` property. Returns: A menu model whose contents will be appended to the context menu.void extraMenu(gio.menu_model.MenuModel propval) @propertySet `extraMenu` property. Params: propval = A menu model whose contents will be appended to the context menu.string imModule() @propertyGet `imModule` property. Returns: Which IM (input method) module should be used for this self.void imModule(string propval) @propertySet `imModule` property. Params: propval = Which IM (input method) module should be used for this self.gtk.types.InputHints inputHints() @propertyGet `inputHints` property. Returns: Additional hints that allow input methods to fine-tune their behaviour.void inputHints(gtk.types.InputHints propval) @propertySet `inputHints` property. Params: propval = Additional hints that allow input methods to fine-tune their behaviour.gtk.types.InputPurpose inputPurpose() @propertyGet `inputPurpose` property. Returns: The purpose of this text field.void inputPurpose(gtk.types.InputPurpose propval) @propertySet `inputPurpose` property. Params: propval = The purpose of this text field.uint invisibleChar() @propertyGet `invisibleChar` property. Returns: The character to used when masking contents (in “password mode”).void invisibleChar(uint propval) @propertySet `invisibleChar` property. Params: propval = The character to used when masking contents (in “password mode”).bool invisibleCharSet() @propertyGet `invisibleCharSet` property. Returns: Whether the invisible char has been set for the [gtk.text.Text].void invisibleCharSet(bool propval) @propertySet `invisibleCharSet` property. Params: propval = Whether the invisible char has been set for the [gtk.text.Text].int maxLength() @propertyGet `maxLength` property. Returns: Maximum number of characters that are allowed.void maxLength(int propval) @propertySet `maxLength` property. Params: propval = Maximum number of characters that are allowed.bool overwriteMode() @propertyGet `overwriteMode` property. Returns: If text is overwritten when typing in the [gtk.text.Text].void overwriteMode(bool propval) @propertySet `overwriteMode` property. Params: propval = If text is overwritten when typing in the [gtk.text.Text].string placeholderText() @propertyGet `placeholderText` property. Returns: The text that will be displayed in the [gtk.text.Text] when it is empty and unfocused.void placeholderText(string propval) @propertySet `placeholderText` property. Params: propval = The text that will be displayed in the [gtk.text.Text] when it is empty and unfocused.bool propagateTextWidth() @propertyGet `propagateTextWidth` property. Returns: Whether the widget should grow and shrink with the content.void propagateTextWidth(bool propval) @propertySet `propagateTextWidth` property. Params: propval = Whether the widget should grow and shrink with the content.int scrollOffset() @propertyGet `scrollOffset` property. Returns: Number of pixels scrolled of the screen to the left.pango.tab_array.TabArray tabs() @propertyGet `tabs` property. Returns: A list of tabstops to apply to the text of the [gtk.text.Text].void tabs(pango.tab_array.TabArray propval) @propertySet `tabs` property. Params: propval = A list of tabstops to apply to the text of the [gtk.text.Text].bool truncateMultiline() @propertyGet `truncateMultiline` property. Returns: When true, pasted multi-line text is truncated to the first line.void truncateMultiline(bool propval) @propertySet `truncateMultiline` property. Params: propval = When true, pasted multi-line text is truncated to the first line.bool visibility() @propertyGet `visibility` property. Returns: If false, the text is masked with the “invisible char”.void visibility(bool propval) @propertySet `visibility` property. Params: propval = If false, the text is masked with the “invisible char”.gtk.text.Text newWithBuffer(gtk.entry_buffer.EntryBuffer buffer)Creates a new [gtk.text.Text] with the specified text buffer.void computeCursorExtents(size_t position, out graphene.rect.Rect strong, out graphene.rect.Rect weak)Determine the positions of the strong and weak cursors if the insertion point in the layout is at position.bool getActivatesDefault()Returns whether pressing Enter will activate the default widget for the window containing self.pango.attr_list.AttrList getAttributes()Gets the attribute list that was set on the [gtk.text.Text].gtk.entry_buffer.EntryBuffer getBuffer()Get the [gtk.entrybuffer.EntryBuffer] object which holds the text for this widget. Returns: A [gtk.entrybuffer.EntryBuffer] object.bool getEnableEmojiCompletion()Returns whether Emoji completion is enabled for this [gtk.text.Text] widget. Returns: true if Emoji completion is enabledgio.menu_model.MenuModel getExtraMenu()Gets the menu model for extra items in the context menu.gtk.types.InputHints getInputHints()Gets the input hints of the [gtk.text.Text]. Returns:gtk.types.InputPurpose getInputPurpose()Gets the input purpose of the [gtk.text.Text]. Returns:dchar getInvisibleChar()Retrieves the character displayed when visibility is set to false.int getMaxLength()Retrieves the maximum allowed length of the text in self.bool getOverwriteMode()Gets whether text is overwritten when typing in the [gtk.text.Text].string getPlaceholderText()Retrieves the text that will be displayed when self is empty and unfocusedbool getPropagateTextWidth()Returns whether the [gtk.text.Text] will grow and shrink with the content. Returns: true if self will propagate the text widthpango.tab_array.TabArray getTabs()Gets the tabstops that were set on the [gtk.text.Text].ushort getTextLength()Retrieves the current length of the text in self.bool getTruncateMultiline()Returns whether the [gtk.text.Text] will truncate multi-line text that is pasted into the widget Returns: true if self will truncate multi-line textbool getVisibility()Retrieves whether the text in self is visible. Returns: true if the text is currently visiblebool grabFocusWithoutSelecting()Causes self to have keyboard focus.void setActivatesDefault(bool activates)If activates is true, pressing Enter will activate the default widget for the window containing self.void setAttributes(pango.attr_list.AttrList attrs = null)Sets attributes that are applied to the text.void setBuffer(gtk.entry_buffer.EntryBuffer buffer)Set the [gtk.entry_buffer.EntryBuffer] object which holds the text for this widget.void setEnableEmojiCompletion(bool enableEmojiCompletion)Sets whether Emoji completion is enabled.void setExtraMenu(gio.menu_model.MenuModel model = null)Sets a menu model to add when constructing the context menu for self.void setInputHints(gtk.types.InputHints hints)Sets input hints that allow input methods to fine-tune their behaviour.void setInputPurpose(gtk.types.InputPurpose purpose)Sets the input purpose of the [gtk.text.Text].void setInvisibleChar(dchar ch)Sets the character to use when in “password mode”.void setMaxLength(int length)Sets the maximum allowed length of the contents of the widget.void setOverwriteMode(bool overwrite)Sets whether the text is overwritten when typing in the [gtk.text.Text].void setPlaceholderText(string text = null)Sets text to be displayed in self when it is empty.void setPropagateTextWidth(bool propagateTextWidth)Sets whether the [gtk.text.Text] should grow and shrink with the content.void setTabs(pango.tab_array.TabArray tabs = null)Sets tabstops that are applied to the text.void setTruncateMultiline(bool truncateMultiline)Sets whether the [gtk.text.Text] should truncate multi-line text that is pasted into the widget.void setVisibility(bool visible)Sets whether the contents of the [gtk.text.Text] are visible or not.void unsetInvisibleChar()Unsets the invisible char.gulong connectActivate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2)Connect to `Activate` signal.gulong connectBackspace(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2)Connect to `Backspace` signal.gulong connectCopyClipboard(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2)Connect to `CopyClipboard` signal.gulong connectCutClipboard(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2)Connect to `CutClipboard` signal.gulong connectDeleteFromCursor(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.types.DeleteType)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == int)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.text.Text)))
&& Parameters!T.length < 4)Connect to `DeleteFromCursor` signal.gulong connectInsertAtCursor(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == string)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.text.Text)))
&& Parameters!T.length < 3)Connect to `InsertAtCursor` signal.gulong connectInsertEmoji(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2)Connect to `InsertEmoji` signal.gulong connectMoveCursor(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.types.MovementStep)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == int)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] == bool)))
&& (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] : gtk.text.Text)))
&& Parameters!T.length < 5)Connect to `MoveCursor` signal.gulong connectPasteClipboard(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2)Connect to `PasteClipboard` signal.gulong connectPreeditChanged(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == string)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.text.Text)))
&& Parameters!T.length < 3)Connect to `PreeditChanged` signal.gulong connectToggleOverwrite(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text.Text)))
&& Parameters!T.length < 2)Connect to `ToggleOverwrite` signal.T activatesDefault(bool propval)Set `activatesDefault` property. Params: propval = Whether to activate the default widget when Enter is pressed. Returns: Builder instance for fluent chainingT attributes(pango.attr_list.AttrList propval)Set `attributes` property. Params: propval = A list of Pango attributes to apply to the text of the [gtk.text.Text].T buffer(gtk.entry_buffer.EntryBuffer propval)Set `buffer` property. Params: propval = The [gtk.entry_buffer.EntryBuffer] object which stores the text. Returns: Builder instance for fluent chainingT enableEmojiCompletion(bool propval)Set `enableEmojiCompletion` property. Params: propval = Whether to suggest Emoji replacements. Returns: Builder instance for fluent chainingT extraMenu(gio.menu_model.MenuModel propval)Set `extraMenu` property. Params: propval = A menu model whose contents will be appended to the context menu. Returns: Builder instance for fluent chainingT imModule(string propval)Set `imModule` property. Params: propval = Which IM (input method) module should be used for this self.T inputHints(gtk.types.InputHints propval)Set `inputHints` property. Params: propval = Additional hints that allow input methods to fine-tune their behaviour. Returns: Builder instance for fluent chainingT inputPurpose(gtk.types.InputPurpose propval)Set `inputPurpose` property. Params: propval = The purpose of this text field.T invisibleChar(uint propval)Set `invisibleChar` property. Params: propval = The character to used when masking contents (in “password mode”). Returns: Builder instance for fluent chainingT invisibleCharSet(bool propval)Set `invisibleCharSet` property. Params: propval = Whether the invisible char has been set for the [gtk.text.Text]. Returns: Builder instance for fluent chainingT maxLength(int propval)Set `maxLength` property. Params: propval = Maximum number of characters that are allowed.T overwriteMode(bool propval)Set `overwriteMode` property. Params: propval = If text is overwritten when typing in the [gtk.text.Text]. Returns: Builder instance for fluent chainingT placeholderText(string propval)Set `placeholderText` property. Params: propval = The text that will be displayed in the [gtk.text.Text] when it is empty and unfocused. Returns: Builder instance for fluent chainingT propagateTextWidth(bool propval)Set `propagateTextWidth` property. Params: propval = Whether the widget should grow and shrink with the content. Returns: Builder instance for fluent chainingT tabs(pango.tab_array.TabArray propval)Set `tabs` property. Params: propval = A list of tabstops to apply to the text of the [gtk.text.Text]. Returns: Builder instance for fluent chainingT truncateMultiline(bool propval)Set `truncateMultiline` property. Params: propval = When true, pasted multi-line text is truncated to the first line. Returns: Builder instance for fluent chainingT visibility(bool propval)Set `visibility` property. Params: propval = If false, the text is masked with the “invisible char”. Returns: Builder instance for fluent chainingFluent builder for [gtk.text.Text]
Text build()