Next: , Previous: GtkLinkButton, Up: Top


20 GtkEntry

A single line text entry field

20.1 Overview

The <gtk-entry> widget is a single line text entry widget. 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.

20.2 Usage

— Class: <gtk-entry>

Derives from <gtk-editable>, <gtk-cell-editable>, <gtk-widget>.

This class defines the following slots:

cursor-position
The current position of the insertion cursor in chars
selection-bound
The position of the opposite end of the selection from the cursor in chars
editable
Whether the entry contents can be edited
max-length
Maximum number of characters for this entry. Zero if no maximum
visibility
FALSE displays the "invisible char" instead of the actual text (password mode)
has-frame
FALSE removes outside bevel from entry
inner-border
Border between text and frame. Overrides the inner-border style property
invisible-char
The character to use when masking entry contents (in "password mode")
activates-default
Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed
width-chars
Number of characters to leave space for in the entry
scroll-offset
Number of pixels of the entry scrolled off the screen to the left
text
The contents of the entry
xalign
The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts.
truncate-multiline
Whether to truncate multiline pastes to one line.
shadow-type
Which kind of shadow to draw around the entry when has-frame is set
— Signal on <gtk-entry>: move-cursor (arg0 <gtk-movement-step>) (arg1 <gint>) (arg2 <gboolean>)
— Signal on <gtk-entry>: copy-clipboard
— Signal on <gtk-entry>: populate-popup (arg0 <gtk-menu>)
— Signal on <gtk-entry>: activate
— Signal on <gtk-entry>: insert-at-cursor (arg0 <gchararray>)
— Signal on <gtk-entry>: delete-from-cursor (arg0 <gtk-delete-type>) (arg1 <gint>)
— Signal on <gtk-entry>: backspace
— Signal on <gtk-entry>: cut-clipboard
— Signal on <gtk-entry>: paste-clipboard
— Signal on <gtk-entry>: toggle-overwrite
— Function: gtk-entry-set-text (self <gtk-entry>) (text mchars)
— Method: set-text

Sets the text in the widget to the given value, replacing the current contents.

entry
a <gtk-entry>.
text
the new text.
— Function: gtk-entry-get-text (self <gtk-entry>) ⇒  (ret mchars)
— Method: get-text

Retrieves the contents of the entry widget. See also gtk-editable-get-chars.

entry
a <gtk-entry>
ret
a pointer to the contents of the widget as a string. This string points to internally allocated storage in the widget and must not be freed, modified or stored.
— Function: gtk-entry-set-visibility (self <gtk-entry>) (visible bool)
— Method: set-visibility

Sets whether the contents of the entry are visible or not. When visibility is set to ‘#f’, characters are displayed as the invisible char, and will also appear that way when the text in the entry widget is copied elsewhere.

The default invisible char is the asterisk '*', but it can be changed with gtk-entry-set-invisible-char.

entry
a <gtk-entry>.
visible
#t’ if the contents of the entry are displayed as plaintext.
— Function: gtk-entry-set-invisible-char (self <gtk-entry>) (ch unsigned-int32)
— Method: set-invisible-char

Sets the character to use in place of the actual text when gtk-entry-set-visibility has been called to set text visibility to ‘#f’. i.e. this is the character used in "password mode" to show the user how many characters have been typed. The default invisible char is an asterisk ('*'). 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.

entry
a <gtk-entry>
ch
a Unicode character
— Function: gtk-entry-set-max-length (self <gtk-entry>) (max int)
— Method: set-max-length

Sets the maximum allowed length of the contents of the widget. If the current contents are longer than the given length, then they will be truncated to fit.

entry
a <gtk-entry>.
max
the maximum length of the entry, or 0 for no maximum. (other than the maximum length of entries.) The value passed in will be clamped to the range 0-65536.
— Function: gtk-entry-get-activates-default (self <gtk-entry>) ⇒  (ret bool)
— Method: get-activates-default

Retrieves the value set by gtk-entry-set-activates-default.

entry
a <gtk-entry>
ret
#t’ if the entry will activate the default widget
— Function: gtk-entry-get-has-frame (self <gtk-entry>) ⇒  (ret bool)
— Method: get-has-frame

Gets the value set by gtk-entry-set-has-frame.

entry
a <gtk-entry>
ret
whether the entry has a beveled frame
— Function: gtk-entry-get-inner-border (self <gtk-entry>) ⇒  (ret <gtk-border>)
— Method: get-inner-border

This function returns the entry's inner-border property. See gtk-entry-set-inner-border for more information.

entry
a <gtk-entry>
ret
the entry's <gtk-border>, or ‘#f’ if none was set.

Since 2.10

— Function: gtk-entry-get-width-chars (self <gtk-entry>) ⇒  (ret int)
— Method: get-width-chars

Gets the value set by gtk-entry-set-width-chars.

entry
a <gtk-entry>
ret
number of chars to request space for, or negative if unset
— Function: gtk-entry-set-activates-default (self <gtk-entry>) (setting bool)
— Method: set-activates-default

If setting is ‘#t’, pressing Enter in the entry will activate the default widget for the window containing the entry. This usually means that the dialog box containing the entry will be closed, since the default widget is usually one of the dialog buttons.

(For experts: if setting is ‘#t’, the entry calls gtk-window-activate-default on the window containing the entry, in the default handler for the "activate" signal.)

entry
a <gtk-entry>
setting
#t’ to activate window's default widget on Enter keypress
— Function: gtk-entry-set-has-frame (self <gtk-entry>) (setting bool)
— Method: set-has-frame

Sets whether the entry has a beveled frame around it.

entry
a <gtk-entry>
setting
new value
— Function: gtk-entry-set-inner-border (self <gtk-entry>) (border <gtk-border>)
— Method: set-inner-border

Sets ‘entry’'s inner-border property to ‘border’, or clears it if ‘#f’ is passed. The inner-border is the area around the entry's text, but inside its frame.

If set, this property overrides the inner-border style property. Overriding the style-provided border is useful when you want to do in-place editing of some text in a canvas or list widget, where pixel-exact positioning of the entry is important.

entry
a <gtk-entry>
border
a <gtk-border>, or ‘#f

Since 2.10

— Function: gtk-entry-set-width-chars (self <gtk-entry>) (n_chars int)
— Method: set-width-chars

Changes the size request of the entry to be about the right size for n-chars characters. Note that it changes the size request, the size can still be affected by how you pack the widget into containers. If n-chars is -1, the size reverts to the default entry size.

entry
a <gtk-entry>
n-chars
width in chars
— Function: gtk-entry-get-invisible-char (self <gtk-entry>) ⇒  (ret unsigned-int32)
— Method: get-invisible-char

Retrieves the character displayed in place of the real characters for entries with visisbility set to false. See gtk-entry-set-invisible-char.

entry
a <gtk-entry>
ret
the current invisible char, or 0, if the entry does not show invisible text at all.
— Function: gtk-entry-set-alignment (self <gtk-entry>) (xalign float)
— Method: set-alignment

Sets the alignment for the contents of the entry. This controls the horizontal positioning of the contents when the displayed text is shorter than the width of the entry.

entry
a <gtk-entry>
xalign
The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts

Since 2.4

— Function: gtk-entry-get-alignment (self <gtk-entry>) ⇒  (ret float)
— Method: get-alignment

Gets the value set by gtk-entry-set-alignment.

entry
a <gtk-entry>
ret
the alignment

Since 2.4

— Function: gtk-entry-get-layout (self <gtk-entry>) ⇒  (ret <pango-layout>)
— Method: get-layout

Gets the <pango-layout> used to display the entry. The layout is useful to e.g. convert text positions to pixel positions, in combination with gtk-entry-get-layout-offsets. The returned layout is owned by the entry and must not be modified or freed by the caller.

Keep in mind that the layout text may contain a preedit string, so gtk-entry-layout-index-to-text-index and gtk-entry-text-index-to-layout-index are needed to convert byte indices in the layout to byte indices in the entry contents.

entry
a <gtk-entry>
ret
the <pango-layout> for this entry
— Function: gtk-entry-get-layout-offsets (self <gtk-entry>) ⇒  (int) (int)
— Method: get-layout-offsets

Obtains the position of the <pango-layout> used to render text in the entry, in widget coordinates. Useful if you want to line up the text in an entry with some other text, e.g. when using the entry to implement editable cells in a sheet widget.

Also useful to convert mouse events into coordinates inside the <pango-layout>, e.g. to take some action if some part of the entry text is clicked.

Note that as the user scrolls around in the entry the offsets will change; you'll need to connect to the "notify::scroll-offset" signal to track this. Remember when using the <pango-layout> functions you need to convert to and from pixels using pango-pixels or <pango-scale>.

Keep in mind that the layout text may contain a preedit string, so gtk-entry-layout-index-to-text-index and gtk-entry-text-index-to-layout-index are needed to convert byte indices in the layout to byte indices in the entry contents.

entry
a <gtk-entry>
x
location to store X offset of layout, or ‘#f
y
location to store Y offset of layout, or ‘#f
— Function: gtk-entry-get-max-length (self <gtk-entry>) ⇒  (ret int)
— Method: get-max-length

Retrieves the maximum allowed length of the text in entry. See gtk-entry-set-max-length.

entry
a <gtk-entry>
ret
the maximum allowed number of characters in <gtk-entry>, or 0 if there is no maximum.
— Function: gtk-entry-get-visibility (self <gtk-entry>) ⇒  (ret bool)
— Method: get-visibility

Retrieves whether the text in entry is visible. See gtk-entry-set-visibility.

entry
a <gtk-entry>
ret
#t’ if the text is currently visible
— Function: gtk-entry-set-completion (self <gtk-entry>) (completion <gtk-entry-completion>)
— Method: set-completion

Sets completion to be the auxiliary completion object to use with entry. All further configuration of the completion mechanism is done on completion using the <gtk-entry-completion> API. Completion is disabled if completion is set to ‘#f’.

entry
A <gtk-entry>.
completion
The <gtk-entry-completion> or ‘#f’.

Since 2.4

— Function: gtk-entry-get-completion (self <gtk-entry>) ⇒  (ret <gtk-entry-completion>)
— Method: get-completion

Returns the auxiliary completion object currently in use by entry.

entry
A <gtk-entry>.
ret
The auxiliary completion object currently in use by entry.

Since 2.4