A single line text entry field
Class GtkEntry
The GtkEntry 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.
When using an entry for passwords and other sensitive information, it can be put into "password mode" using set_visibility(). 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 set_invisible_char(). Since 2.16, GTK+ displays a warning when Caps Lock or input methods might interfere with entering text in a password entry. The warning can be turned off with the "caps-lock-warning" property.
Since 2.16, GtkEntry has the ability to display progress or activity information behind the text. To make an entry display such information, use set_progress_fraction() or set_progress_pulse_step().
Additionally, GtkEntry can show icons at either side of the entry. These icons can be activatable by clicking, can be set up as drag source and can have tooltips. To add an icon, use set_icon_from_gicon() or one of the various other functions that set an icon from a stock id, an icon name or a pixbuf. To trigger an action when the user clicks an icon, connect to the "icon-press" signal. To allow DND operations from an icon, use set_icon_drag_source(). To set a tooltip on an icon, use set_icon_tooltip_text() or the corresponding function for markup.
Note that functionality or information that is only available by clicking on an icon in an entry may not be accessible at all to users which are not able to use a mouse or other pointing device. It is therefore recommended that any such functionality should also be available by other means, e.g. via the context menu of the entry.
Methods | |
get_activates_default | Retrieves the value set by set_activates_default(). |
get_alignment | Gets the value set by gtk_entry_set_alignment(). |
get_buffer | Get the GtkEntryBuffer object which holds the text for this widget. |
get_cursor_hadjustment | Retrieves the horizontal cursor adjustment for the entry |
get_has_frame | Gets the value set by gtk_entry_set_has_frame(). |
get_icon_activatable | Returns whether the icon is activatable. |
get_icon_at_pos | Finds the icon at the given position and return its index. |
get_icon_name | Retrieves the icon name used for the icon, or NULL if there is no icon or if the icon was set by some other method (e.g., by pixbuf, stock or gicon). |
get_icon_pixbuf | Retrieves the image used for the icon. |
get_icon_sensitive | Returns whether the icon appears sensitive or insensitive. |
get_icon_stock | Retrieves the stock id used for the icon, or NULL if there is no icon or if the icon was set by some other method (e.g., by pixbuf, icon name or gicon). |
get_icon_storage_type | Gets the type of representation being used by the icon to store image data. |
get_icon_tooltip_markup | Gets the contents of the tooltip on the icon at the specified position in entry. |
get_icon_tooltip_text | Gets the contents of the tooltip on the icon at the specified position in entry. |
get_invisible_char | Retrieves the character displayed in place of the real characters for entries with visibility set to false. |
get_layout_offsets | Obtains the position of the PangoLayout used to render text in the entry, in widget coordinates. |
get_max_length | Retrieves the maximum allowed length of the text in entry. |
get_overwrite_mode | Gets the value set by gtk_entry_set_overwrite_mode(). |
get_progress_fraction | Returns the current fraction of the task that's been completed. |
get_progress_pulse_step | Retrieves the pulse step set with gtk_entry_set_progress_pulse_step(). |
get_text | Retrieves the contents of the entry widget. |
get_text_length | Retrieves the current length of the text in entry. |
get_visibility | Retrieves whether the text in entry is visible. |
get_width_chars | Gets the value set by gtk_entry_set_width_chars(). |
layout_index_to_text_index | Converts from a position in the entry contents (returned by gtk_entry_get_text()) to a position in the entry's PangoLayout (returned by gtk_entry_get_layout(), with text retrieved via pango_layout_get_text()). |
new_with_buffer | Creates a new entry with the specified text buffer. |
new_with_max_length | Creates a new GtkEntry widget with the given maximum length. |
progress_pulse | Indicates that some progress is made, but you don't know how much. |
set_activates_default | If setting is TRUE, pressing Enter in the entry will activate the default widget for the window containing the entry. |
set_alignment | Sets the alignment for the contents of the entry. |
set_buffer | Set the GtkEntryBuffer object which holds the text for this widget. |
set_cursor_hadjustment | Hooks up an adjustment to the cursor position in an entry, so that when the cursor is moved, the adjustment is scrolled to show that position. |
set_has_frame | Sets whether the entry has a beveled frame around it. |
set_icon_activatable | Sets whether the icon is activatable. |
set_icon_from_icon_name | Sets the icon shown in the entry at the specified position from the current icon theme. |
set_icon_from_pixbuf | Sets the icon shown in the specified position using a pixbuf. |
set_icon_from_stock | Sets the icon shown in the entry at the specified position from a stock image. |
set_icon_sensitive | Sets the sensitivity for the specified icon. |
set_icon_tooltip_markup | Sets tooltip as the contents of the tooltip for the icon at the specified position. |
set_icon_tooltip_text | Sets tooltip as the contents of the tooltip for the icon at the specified position. |
set_invisible_char | Sets the entry invisible char |
set_max_length | Sets the maximum allowed length of the contents of the widget. |
set_overwrite_mode | Sets whether the text is overwritten when typing in the GtkEntry. |
set_progress_fraction | Causes the entry's progress indicator to "fill in" the given fraction of the bar. |
set_progress_pulse_step | Sets the fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse(). |
set_text | Sets the text in the widget to the given value, replacing the current contents. |
set_visiblity | Sets whether the contents of the entry are visible or not. |
set_width_chars | Changes the size request of the entry to be about the right size for n_chars characters. |
signal_activate | A keybinding signal which gets emitted when the user activates the entry. |
signal_backspace | The backspace signal is a keybinding signal which gets emitted when the user asks for it. |
signal_copy_clipboard | The copy-clipboard signal is a keybinding signal which gets emitted to copy the selection to the clipboard. |
signal_cut_clipboard | The cut-clipboard signal is a keybinding signal which gets emitted to cut the selection to the clipboard. |
signal_delete_from_cursor | The delete-from-cursor signal is a keybinding signal which gets emitted when the user initiates a text deletion. |
signal_icon_press | The ::icon-press signal is emitted when an activatable icon is clicked. |
signal_icon_release | The icon-release signal is emitted on the button release from a mouse click over an activatable icon. |
signal_insert_at_cursor | The insert-at-cursor signal is a keybinding signal which gets emitted when the user initiates the insertion of a fixed string at the cursor. |
signal_move_cursor | The move-cursor signal is a keybinding signal which gets emitted when the user initiates a cursor movement. |
signal_paste_clipboard | The paste-clipboard signal is a keybinding signal which gets emitted to paste the contents of the clipboard into the text view. |
signal_populate_popup | The populate-popup signal gets emitted before showing the context menu of the entry. |
signal_preedit_changed | 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. |
signal_toggle_overwrite | The toggle-overwrite signal is a keybinding signal which gets emitted to toggle the overwrite mode of the entry. |
text_index_to_layout_index | Converts from a position in the entry's PangoLayout (returned by gtk_entry_get_layout()) to a position in the entry contents (returned by gtk_entry_get_text()). |
unset_invisible_char | Unsets the invisible char previously set with set_invisible_char(). |
Retrieves the value set by set_activates_default().
GtkEntry.get_activates_default()
Return | (boolean) true if the entry will activate the default widget |
Gets the value set by gtk_entry_set_alignment().
GtkEntry.get_alignment()
Return | the alignment |
Get the GtkEntryBuffer object which holds the text for this widget.
GtkEntry.get_buffer()
Return | A GtkEntryBuffer object. |
Retrieves the horizontal cursor adjustment for the entry
GtkEntry.get_cursor_hadjustment()
Return | the horizontal cursor adjustment, or NULL if none has been set. |
Gets the value set by gtk_entry_set_has_frame().
GtkEntry.get_has_frame()
Return | whether the entry has a beveled frame |
Returns whether the icon is activatable.
GtkEntry.get_icon_activatable( icon_pos )
icon_pos | Icon position (GtkEntryIconPosition). |
Return | TRUE if the icon is activatable. |
Finds the icon at the given position and return its index.
GtkEntry.get_icon_at_pos( x, y )
x | the x coordinate of the position to find |
y | the y coordinate of the position to find |
Return | the index of the icon at the given position, or -1. |
If x, y doesn't lie inside an icon, -1 is returned. This function is intended for use in a "query-tooltip" signal handler.
Retrieves the icon name used for the icon, or NULL if there is no icon or if the icon was set by some other method (e.g., by pixbuf, stock or gicon).
GtkEntry.get_icon_name( icon_pos )
icon_pos | Icon position (GtkEntryIconPosition). |
Return | An icon name, or NULL if no icon is set or if the icon wasn't set from an icon name |
Retrieves the image used for the icon.
GtkEntry.get_icon_pixbuf( icon_pos )
icon_pos | Icon position (GtkEntryIconPosition). |
Return | A GdkPixbuf, or NULL if no icon is set for this position. |
Unlike the other methods of setting and getting icon data, this method will work regardless of whether the icon was set using a GdkPixbuf, a GIcon, a stock item, or an icon name.
Returns whether the icon appears sensitive or insensitive.
GtkEntry.get_icon_sensitive( icon_pos )
icon_pos | Icon position (GtkEntryIconPosition). |
Return | TRUE if the icon is sensitive. |
Retrieves the stock id used for the icon, or NULL if there is no icon or if the icon was set by some other method (e.g., by pixbuf, icon name or gicon).
GtkEntry.get_icon_stock( icon_pos )
icon_pos | Icon position (GtkEntryIconPosition). |
Return | A stock id, or NULL if no icon is set or if the icon wasn't set from a stock id. |
Gets the type of representation being used by the icon to store image data.
GtkEntry.get_icon_storage_type( icon_pos )
icon_pos | Icon position (GtkEntryIconPosition). |
Return | image representation being used |
If the icon has no image data, the return value will be GTK_IMAGE_EMPTY.
Gets the contents of the tooltip on the icon at the specified position in entry.
GtkEntry.get_icon_tooltip_markup( icon_pos )
icon_pos | Icon position (GtkEntryIconPosition). |
Return | the tooltip text, or NULL. |
Gets the contents of the tooltip on the icon at the specified position in entry.
GtkEntry.get_icon_tooltip_text( icon_pos )
icon_pos | Icon position (GtkEntryIconPosition). |
Return | the tooltip text, or NULL. |
Retrieves the character displayed in place of the real characters for entries with visibility set to false.
GtkEntry.get_invisible_char()
Return | the current invisible char, or "", if the entry does not show invisible text at all. |
Obtains the position of the PangoLayout used to render text in the entry, in widget coordinates.
GtkEntry.get_layout_offsets()
Return | an array ( X offset, Y offset ). |
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 PangoLayout, 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 PangoLayout 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.
Retrieves the maximum allowed length of the text in entry.
GtkEntry.get_max_length()
Return | the maximum allowed number of characters in GtkEntry, or 0 if there is no maximum. |
Gets the value set by gtk_entry_set_overwrite_mode().
GtkEntry.get_overwrite_mode()
Return | whether the text is overwritten when typing. |
Returns the current fraction of the task that's been completed.
GtkEntry.get_progress_fraction()
Return | a fraction from 0.0 to 1.0 |
Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
GtkEntry.get_progress_pulse_step()
Return | a fraction from 0.0 to 1.0 |
Retrieves the contents of the entry widget.
GtkEntry.get_text()
Return | the contents of the widget as a string. |
Retrieves the current length of the text in entry.
GtkEntry.get_text_length()
Return | the current number of characters in GtkEntry, or 0 if there are none. |
Retrieves whether the text in entry is visible.
GtkEntry.get_visibility()
Return | TRUE if the text is currently visible |
Gets the value set by gtk_entry_set_width_chars().
GtkEntry.get_width_chars()
Return | number of chars to request space for, or negative if unset |
Converts from a position in the entry contents (returned by gtk_entry_get_text()) to a position in the entry's PangoLayout (returned by gtk_entry_get_layout(), with text retrieved via pango_layout_get_text()).
GtkEntry.layout_index_to_text_index( layout_index )
layout_index | byte index into the entry layout text |
Return | byte index into the entry contents |
Creates a new entry with the specified text buffer.
GtkEntry.new_with_buffer( buffer )
buffer | The GtkEntryBuffer to use for the new GtkEntry. |
Creates a new GtkEntry widget with the given maximum length.
GtkEntry.new_with_max_length( max )
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. |
gtk_entry_new_with_max_length has been deprecated since version 2.0 and should not be used in newly-written code. Use gtk_entry_set_max_length() instead.
Indicates that some progress is made, but you don't know how much.
GtkEntry.progress_pulse()
Causes the entry's progress indicator to enter "activity mode," where a block bounces back and forth. Each call to gtk_entry_progress_pulse() causes the block to move by a little bit (the amount of movement per pulse is determined by gtk_entry_set_progress_pulse_step()).
If setting is TRUE, pressing Enter in the entry will activate the default widget for the window containing the entry.
GtkEntry.set_activates_default( setting )
setting | TRUE to activate window's default widget on Enter keypress |
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 TRUE, the entry calls gtk_window_activate_default() on the window containing the entry, in the default handler for the "activate" signal.)
Sets the alignment for the contents of the entry.
GtkEntry.set_alignment( xalign )
xalign | The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts |
This controls the horizontal positioning of the contents when the displayed text is shorter than the width of the entry.
Set the GtkEntryBuffer object which holds the text for this widget.
GtkEntry.set_buffer( buffer )
buffer | a GtkEntryBuffer |
Hooks up an adjustment to the cursor position in an entry, so that when the cursor is moved, the adjustment is scrolled to show that position.
GtkEntry.set_cursor_hadjustment( adjustment )
adjustment | an adjustment which should be adjusted when the cursor is moved, or NULL |
See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining the adjustment.
The adjustment has to be in pixel units and in the same coordinate system as the entry.
Sets whether the entry has a beveled frame around it.
GtkEntry.set_has_frame( setting )
setting | new value (boolean). |
Sets whether the icon is activatable.
GtkEntry.set_icon_activatable( icon_pos, activatable )
icon_pos | Icon position (GtkEntryIconPosition). |
activatable | TRUE if the icon should be activatable. |
Sets the icon shown in the entry at the specified position from the current icon theme.
GtkEntry.set_icon_from_icon_name( icon_pos, icon_name )
icon_pos | The position at which to set the icon (GtkEntryIconPosition). |
icon_name | An icon name, or NULL. |
If the icon name isn't known, a "broken image" icon will be displayed instead.
If icon_name is NULL, no icon will be shown in the specified position.
Sets the icon shown in the specified position using a pixbuf.
GtkEntry.set_icon_from_pixbuf( icon_pos, pixbuf )
icon_pos | Icon position (GtkEntryIconPosition). |
pixbuf | A GdkPixbuf, or NULL. |
If pixbuf is NULL, no icon will be shown in the specified position.
Sets the icon shown in the entry at the specified position from a stock image.
GtkEntry.set_icon_from_stock( icon_pos, stock_id )
icon_pos | Icon position (GtkEntryIconPosition). |
stock_id | The name of the stock item, or NULL. |
If stock_id is NULL, no icon will be shown in the specified position.
Sets the sensitivity for the specified icon.
GtkEntry.set_icon_sensitive( icon_pos, sensitive )
icon_pos | Icon position (GtkEntryIconPosition). |
sensitive | Specifies whether the icon should appear sensitive or insensitive |
Sets tooltip as the contents of the tooltip for the icon at the specified position.
GtkEntry.set_icon_tooltip_markup( icon_pos, tooltip )
icon_pos | Icon position (GtkEntryIconPosition). |
tooltip | the contents of the tooltip for the icon, or NULL. |
tooltip is assumed to be marked up with the Pango text markup language.
Use NULL for tooltip to remove an existing tooltip.
See also gtk_widget_set_tooltip_markup() and gtk_enty_set_icon_tooltip_text().
Sets tooltip as the contents of the tooltip for the icon at the specified position.
GtkEntry.set_icon_tooltip_text( icon_pos, tooltip )
icon_pos | Icon position (GtkEntryIconPosition). |
tooltip | the contents of the tooltip for the icon, or NULL. |
Use NULL for tooltip to remove an existing tooltip.
Sets the entry invisible char
GtkEntry.set_invisible_char( ch )
ch | a character |
Sets the character to use in place of the actual text when set_visibility() has been called to set text visibility to false. i.e. this is the character used in "password mode" to show the user how many characters have been typed. By default, GTK+ picks the best invisible char available in the current font. If you set the invisible char to "", then the user will get no feedback at all; there will be no text on the screen as they type.
Sets the maximum allowed length of the contents of the widget.
GtkEntry.set_max_length( max )
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.
If the current contents are longer than the given length, then they will be truncated to fit.
Sets whether the text is overwritten when typing in the GtkEntry.
GtkEntry.set_overwrite_mode( overwrite )
overwrite | new value (boolean). |
Causes the entry's progress indicator to "fill in" the given fraction of the bar.
GtkEntry.set_progress_fraction( fraction )
fraction | fraction of the task that's been completed. |
The fraction should be between 0.0 and 1.0, inclusive.
Sets the fraction of total entry width to move the progress bouncing block for each call to gtk_entry_progress_pulse().
GtkEntry.set_progress_pulse_step( fraction )
fraction | fraction between 0.0 and 1.0 |
Sets the text in the widget to the given value, replacing the current contents.
GtkEntry.set_text( text )
text | the new text |
Sets whether the contents of the entry are visible or not.
GtkEntry.set_visiblity( visible )
visible | (boolean) true if the contents of the entry are displayed as plaintext |
When visibility is set to false, characters are displayed as the invisible char, and will also appear that way when the text in the entry widget is copied elsewhere.
By default, GTK+ picks the best invisible character available in the current font, but it can be changed with set_invisible_char().
Changes the size request of the entry to be about the right size for n_chars characters.
GtkEntry.set_width_chars( n_chars )
n_chars | width in chars |
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.
A keybinding signal which gets emitted when the user activates the entry.
GtkEntry.signal_activate()
Applications should not connect to it, but may emit it with g_signal_emit_by_name() if they need to control activation programmatically.
The default bindings for this signal are all forms of the Enter key.
The backspace signal is a keybinding signal which gets emitted when the user asks for it.
GtkEntry.signal_backspace()
The default bindings for this signal are Backspace and Shift-Backspace.
The copy-clipboard signal is a keybinding signal which gets emitted to copy the selection to the clipboard.
GtkEntry.signal_copy_clipboard()
The default bindings for this signal are Ctrl-c and Ctrl-Insert.
The cut-clipboard signal is a keybinding signal which gets emitted to cut the selection to the clipboard.
GtkEntry.signal_cut_clipboard()
The default bindings for this signal are Ctrl-x and Shift-Delete.
The delete-from-cursor signal is a keybinding signal which gets emitted when the user initiates a text deletion.
GtkEntry.signal_delete_from_cursor()
If the type is GTK_DELETE_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.
The ::icon-press signal is emitted when an activatable icon is clicked.
GtkEntry.signal_icon_press()
Note: Currently not implemented.
The icon-release signal is emitted on the button release from a mouse click over an activatable icon.
GtkEntry.signal_icon_release()
Note: Currently not implemented.
The insert-at-cursor signal is a keybinding signal which gets emitted when the user initiates the insertion of a fixed string at the cursor.
GtkEntry.signal_insert_at_cursor()
This signal has no default bindings.
The move-cursor signal is a keybinding signal which gets emitted when the user initiates a cursor movement.
GtkEntry.signal_move_cursor()
If the cursor is not visible in entry, this signal causes the viewport to be moved instead.
Applications should not connect to it, but may emit it with g_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 the Shift modifer does not. There are too many key combinations to list them all here.
- Arrow keys move by individual characters/lines
The paste-clipboard signal is a keybinding signal which gets emitted to paste the contents of the clipboard into the text view.
GtkEntry.signal_paste_clipboard()
The default bindings for this signal are Ctrl-v and Shift-Insert.
The populate-popup signal gets emitted before showing the context menu of the entry.
GtkEntry.signal_populate_popup()
If you need to add items to the context menu, connect to this signal and append your menuitems to the menu.
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.
GtkEntry.signal_preedit_changed()
The toggle-overwrite signal is a keybinding signal which gets emitted to toggle the overwrite mode of the entry.
GtkEntry.signal_toggle_overwrite()
The default bindings for this signal is Insert.
Converts from a position in the entry's PangoLayout (returned by gtk_entry_get_layout()) to a position in the entry contents (returned by gtk_entry_get_text()).
GtkEntry.text_index_to_layout_index( text_index )
text_index | byte index into the entry contents |
Return | byte index into the entry layout text |
Unsets the invisible char previously set with set_invisible_char().
GtkEntry.unset_invisible_char()
So that the default invisible char is used again.