Gtk.Entry
Gtk.Entry — A single line text entry field
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Entry
├── Gtk.SearchEntry
╰── Gtk.SpinButton
Functions:
- new
() -> Gtk.Widget
- new_with_buffer
(buffer:Gtk.EntryBuffer) -> Gtk.Widget
- get_buffer
(self) -> Gtk.EntryBuffer
- set_buffer
(self, buffer:Gtk.EntryBuffer)
- set_text
(self, text:str)
- get_text
(self) -> str
- get_text_length
(self) -> int
- get_text_area
(self) -> text_area:Gdk.Rectangle
- set_visibility
(self, visible:bool)
- set_invisible_char
(self, ch:str)
- unset_invisible_char
(self)
- set_max_length
(self, max:int)
- get_activates_default
(self) -> bool
- get_has_frame
(self) -> bool
- get_inner_border
(self) -> Gtk.Border or None
- get_width_chars
(self) -> int
- get_max_width_chars
(self) -> int
- set_activates_default
(self, setting:bool)
- set_has_frame
(self, setting:bool)
- set_inner_border
(self, border:Gtk.Border=None)
- set_width_chars
(self, n_chars:int)
- set_max_width_chars
(self, n_chars:int)
- get_invisible_char
(self) -> str
- set_alignment
(self, xalign:float)
- get_alignment
(self) -> float
- set_placeholder_text
(self, text:str=None)
- get_placeholder_text
(self) -> str
- set_overwrite_mode
(self, overwrite:bool)
- get_overwrite_mode
(self) -> bool
- get_layout
(self) -> Pango.Layout
- get_layout_offsets
(self) -> x:int, y:int
- layout_index_to_text_index
(self, layout_index:int) -> int
- text_index_to_layout_index
(self, text_index:int) -> int
- set_attributes
(self, attrs:Pango.AttrList)
- get_attributes
(self) -> Pango.AttrList or None
- get_max_length
(self) -> int
- get_visibility
(self) -> bool
- set_completion
(self, completion:Gtk.EntryCompletion=None)
- get_completion
(self) -> Gtk.EntryCompletion
- set_cursor_hadjustment
(self, adjustment:Gtk.Adjustment=None)
- get_cursor_hadjustment
(self) -> Gtk.Adjustment or None
- set_progress_fraction
(self, fraction:float)
- get_progress_fraction
(self) -> float
- set_progress_pulse_step
(self, fraction:float)
- get_progress_pulse_step
(self) -> float
- progress_pulse
(self)
- im_context_filter_keypress
(self, event:Gdk.EventKey) -> bool
- reset_im_context
(self)
- get_tabs
(self) -> Pango.TabArray or None
- set_tabs
(self, tabs:Pango.TabArray)
- set_icon_from_pixbuf
(self, icon_pos:Gtk.EntryIconPosition, pixbuf:GdkPixbuf.Pixbuf=None)
- set_icon_from_stock
(self, icon_pos:Gtk.EntryIconPosition, stock_id:str=None)
- set_icon_from_icon_name
(self, icon_pos:Gtk.EntryIconPosition, icon_name:str=None)
- set_icon_from_gicon
(self, icon_pos:Gtk.EntryIconPosition, icon:Gio.Icon=None)
- get_icon_storage_type
(self, icon_pos:Gtk.EntryIconPosition) -> Gtk.ImageType
- get_icon_pixbuf
(self, icon_pos:Gtk.EntryIconPosition) -> GdkPixbuf.Pixbuf or None
- get_icon_stock
(self, icon_pos:Gtk.EntryIconPosition) -> str
- get_icon_name
(self, icon_pos:Gtk.EntryIconPosition) -> str or None
- get_icon_gicon
(self, icon_pos:Gtk.EntryIconPosition) -> Gio.Icon or None
- set_icon_activatable
(self, icon_pos:Gtk.EntryIconPosition, activatable:bool)
- get_icon_activatable
(self, icon_pos:Gtk.EntryIconPosition) -> bool
- set_icon_sensitive
(self, icon_pos:Gtk.EntryIconPosition, sensitive:bool)
- get_icon_sensitive
(self, icon_pos:Gtk.EntryIconPosition) -> bool
- get_icon_at_pos
(self, x:int, y:int) -> int
- set_icon_tooltip_text
(self, icon_pos:Gtk.EntryIconPosition, tooltip:str=None)
- get_icon_tooltip_text
(self, icon_pos:Gtk.EntryIconPosition) -> str or None
- set_icon_tooltip_markup
(self, icon_pos:Gtk.EntryIconPosition, tooltip:str=None)
- get_icon_tooltip_markup
(self, icon_pos:Gtk.EntryIconPosition) -> str or None
- set_icon_drag_source
(self, icon_pos:Gtk.EntryIconPosition, target_list:Gtk.TargetList, actions:Gdk.DragAction)
- get_current_icon_drag_source
(self) -> int
- get_icon_area
(self, icon_pos:Gtk.EntryIconPosition) -> icon_area:Gdk.Rectangle
- set_input_purpose
(self, purpose:Gtk.InputPurpose)
- get_input_purpose
(self) -> Gtk.InputPurpose
- set_input_hints
(self, hints:Gtk.InputHints)
- get_input_hints
(self) -> Gtk.InputHints
- grab_focus_without_selecting
(self)
Signals:
- “activate”
(entry, user_data)
- “backspace”
(entry, user_data)
- “copy-clipboard”
(entry, user_data)
- “cut-clipboard”
(entry, user_data)
- “delete-from-cursor”
(entry, type, count, user_data)
- “icon-press”
(entry, icon_pos, event, user_data)
- “icon-release”
(entry, icon_pos, event, user_data)
- “insert-at-cursor”
(entry, string, user_data)
- “move-cursor”
(entry, step, count, extend_selection, user_data)
- “paste-clipboard”
(entry, user_data)
- “populate-popup”
(entry, popup, user_data)
- “preedit-changed”
(entry, preedit, user_data)
Description:
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.
When using an entry for passwords and other sensitive information, it can be put into password mode
using Gtk.Entry::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
Gtk.Entry::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
Since 2.16, Gtk.Entry
has the ability to display progress or activity information behind the text. To make an entry display such information, use Gtk.Entry::set_progress_fraction()
or Gtk.Entry::set_progress_pulse_step()
.
Additionally, Gtk.Entry
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 Gtk.Entry::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 Gtk.Entry::icon
-press signal. To allow DND operations from an icon, use Gtk.Entry::set_icon_drag_source()
. To set a tooltip on an icon, use Gtk.Entry::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.
Function Details:
new()
new () -> Gtk.Widget
Creates a new entry.
- Returns:
a new
Gtk.Entry
.
new_with_buffer()
new_with_buffer (buffer:Gtk.EntryBuffer) -> Gtk.Widget
Creates a new entry with the specified text buffer.
Returns: a new Gtk.Entry
Since: 2.18
get_buffer()
get_buffer (self) -> Gtk.EntryBuffer
Get the Gtk.EntryBuffer
object which holds the text forthis widget.
Returns: A
Gtk.EntryBuffer
object.Since: 2.18
set_buffer()
set_buffer (self, buffer:Gtk.EntryBuffer)
Set the Gtk.EntryBuffer
object which holds the text forthis widget.
- Since: 2.18
set_text()
set_text (self, text:str)
Sets the text in the widget to the givenvalue, replacing the current contents.
See Gtk.Entry:buffer_set_text()
.
get_text()
get_text (self) -> str
Retrieves the contents of the entry widget.See also `Gtk.Editable:get_chars
().
This is equivalent to:
Gtk.EntryBuffer` *buffer;buffer = Gtk.Entry:get_buffer (entry);Gtk.Entry:buffer_get_text (buffer);
- Returns: a pointer to the contents of the widget as astring. This string points to internally allocatedstorage in the widget and must not be freed, modified orstored.
get_text_length()
get_text_length (self) -> int
Retrieves the current length of the text inentry
.
This is equivalent to:
Gtk.EntryBuffer
*buffer;buffer = Gtk.Entry:get_buffer (entry);Gtk.Entry:buffer_get_length (buffer);
Returns: the current number of charactersin
Gtk.Entry
, or 0 if there are none.Since: 2.14
get_text_area()
get_text_area (self) -> text_area:Gdk.Rectangle
Gets the area where the entry’s text is drawn. This function isuseful when drawing something to the entry in a draw callback.
If the entry is not realized, text_area
is filled with zeros.
See also Gtk.Entry:get_icon_area()
.
- Since: 3.0
set_visibility()
set_visibility (self, visible:bool)
Sets whether the contents of the entry are visible or not.When visibility is set to FALSE
, characters are displayedas the invisible char, and will also appear that way whenthe text in the entry widget is copied elsewhere.
By default, GTK+ picks the best invisible character availablein the current font, but it can be changed withGtk.Entry:set_invisible_char()
.
Note that you probably want to set “input-purpose”to GTK_INPUT_PURPOSE_PASSWORD
or GTK_INPUT_PURPOSE_PIN
toinform input methods about the purpose of this entry,in addition to setting visibility to FALSE
.
set_invisible_char()
set_invisible_char (self, ch:str)
Sets the character to use in place of the actual text whenGtk.Entry:set_visibility()
has been called to set text visibilityto FALSE
. i.e. this is the character used in “password mode” toshow the user how many characters have been typed. By default, GTK+picks the best invisible char available in the current font. If youset the invisible char to 0, then the user will get no feedbackat all; there will be no text on the screen as they type.
unset_invisible_char()
unset_invisible_char (self)
Unsets the invisible char previously set withGtk.Entry:set_invisible_char()
. So that thedefault invisible char is used again.
- Since: 2.16
set_max_length()
set_max_length (self, max:int)
Sets the maximum allowed length of the contents of the widget. Ifthe current contents are longer than the given length, then theywill be truncated to fit.
This is equivalent to:
Gtk.EntryBuffer
*buffer;buffer = Gtk.Entry:get_buffer (entry);Gtk.Entry:buffer_set_max_length (buffer, max);
get_activates_default()
get_activates_default (self) -> bool
Retrieves the value set by Gtk.Entry:set_activates_default()
.
- Returns:
True
if the entry will activate the default widget
get_has_frame()
get_has_frame (self) -> bool
Gets the value set by Gtk.Entry:set_has_frame()
.
- Returns: whether the entry has a beveled frame
get_inner_border()
get_inner_border (self) -> Gtk.Border or None
Gtk.Entry:get_inner_border
has been deprecated since version 3.4 and should not be used in newly-written code.
Use the standard border and padding CSS properties (through objects like Gtk.StyleContext
and Gtk.CssProvider);
the value returned by this function is ignored by Gtk.Entry
.
This function returns the entry’s “inner-border” property. SeeGtk.Entry:set_inner_border()
for more information.
Returns: the entry’s
Gtk.Border
, orNone
if none was set.Since: 2.10
get_width_chars()
get_width_chars (self) -> int
Gets the value set by Gtk.Entry:set_width_chars()
.
- Returns: number of chars to request space for, or negative if unset
get_max_width_chars()
get_max_width_chars (self) -> int
Retrieves the desired maximum width of entry
, in characters.See Gtk.Entry:set_max_width_chars()
.
Returns: the maximum width of the entry, in characters
Since: 3.12
set_activates_default()
set_activates_default (self, setting:bool)
If setting
is True
, pressing Enter in the entry
will activate the defaultwidget for the window containing the entry. This usually means thatthe dialog box containing the entry will be closed, since the defaultwidget 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, inthe default handler for the “activate” signal.)
set_has_frame()
set_has_frame (self, setting:bool)
Sets whether the entry has a beveled frame around it.
set_inner_border()
set_inner_border (self, border:Gtk.Border=None)
Gtk.Entry:set_inner_border
has been deprecated since version 3.4 and should not be used in newly-written code.
Use the standard border and padding CSS properties (through objects like Gtk.StyleContext
and Gtk.CssProvider);
the value set with this function is ignored by Gtk.Entry
.
Sets entry
’s inner-border property to border
, or clears it if None
is passed. The inner-border is the area around the entry’s text, butinside its frame.
If set, this property overrides the inner-border style property.Overriding the style-provided border is useful when you want to doin-place editing of some text in a canvas or list widget, wherepixel-exact positioning of the entry is important.
- Since: 2.10
set_width_chars()
set_width_chars (self, n_chars:int)
Changes the size request of the entry to be about the right sizefor n_chars
characters. Note that it changes the sizerequest, the size can still be affected byhow you pack the widget into containers. If n_chars
is -1, thesize reverts to the default entry size.
set_max_width_chars()
set_max_width_chars (self, n_chars:int)
Sets the desired maximum width in characters of entry
.
- Since: 3.12
get_invisible_char()
get_invisible_char (self) -> str
Retrieves the character displayed in place of the real charactersfor entries with visibility set to false. See Gtk.Entry:set_invisible_char()
.
- Returns: the current invisible char, or 0, if the entry does notshow invisible text at all.
set_alignment()
set_alignment (self, xalign:float)
Sets the alignment for the contents of the entry. This controlsthe horizontal positioning of the contents when the displayedtext is shorter than the width of the entry.
- Since: 2.4
get_alignment()
get_alignment (self) -> float
Gets the value set by Gtk.Entry:set_alignment()
.
Returns: the alignment
Since: 2.4
set_placeholder_text()
set_placeholder_text (self, text:str=None)
Sets text to be displayed in entry
when it is empty and unfocused.This can be used to give a visual hint of the expected contents ofthe Gtk.Entry
.
Note that since the placeholder text gets removed when the entryreceived focus, using this feature is a bit problematic if the entryis given the initial focus in a window. Sometimes this can beworked around by delaying the initial focus setting until thefirst key event arrives.
- Since: 3.2
get_placeholder_text()
get_placeholder_text (self) -> str
Retrieves the text that will be displayed when entry
is empty and unfocused
Returns: a pointer to the placeholder text as a string. This string points to internally allocatedstorage in the widget and must not be freed, modified or stored.
Since: 3.2
set_overwrite_mode()
set_overwrite_mode (self, overwrite:bool)
Sets whether the text is overwritten when typing in the Gtk.Entry
.
- Since: 2.14
get_overwrite_mode()
get_overwrite_mode (self) -> bool
Gets the value set by Gtk.Entry:set_overwrite_mode()
.
Returns: whether the text is overwritten when typing.
Since: 2.14
get_layout()
get_layout (self) -> Pango.Layout
Gets the PangoLayout used to display the entry.The layout is useful to e.g. convert text positions topixel 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, soGtk.Entry:layout_index_to_text_index()
andGtk.Entry:text_index_to_layout_index()
are needed to convert byteindices in the layout to byte indices in the entry contents.
- Returns: the PangoLayout for this entry.
get_layout_offsets()
get_layout_offsets (self) -> x:int, y:int
Obtains the position of the PangoLayout used to render textin the entry, in widget coordinates. Useful if you want to lineup the text in an entry with some other text, e.g. when using theentry to implement editable cells in a sheet widget.
Also useful to convert mouse events into coordinates inside thePangoLayout, e.g. to take some action if some part of the entry textis clicked.
Note that as the user scrolls around in the entry the offsets willchange; you’ll need to connect to the “notify::scroll-offset”signal to track this. Remember when using the PangoLayoutfunctions you need to convert to and from pixels usingPANGO_PIXELS()
or PANGO_SCALE.
Keep in mind that the layout text may contain a preedit string, soGtk.Entry:layout_index_to_text_index()
andGtk.Entry:text_index_to_layout_index()
are needed to convert byteindices in the layout to byte indices in the entry contents.
layout_index_to_text_index()
layout_index_to_text_index (self, layout_index:int) -> int
Converts from a position in the entry contents (returnedby Gtk.Entry:get_text()
) to a position in theentry’s PangoLayout (returned by Gtk.Entry:get_layout()
,with text retrieved via pango_layout_get_text()
).
- Returns: byte index into the entry contents
text_index_to_layout_index()
text_index_to_layout_index (self, text_index:int) -> int
Converts from a position in the entry’s PangoLayout (returned byGtk.Entry:get_layout()
) to a position in the entry contents(returned by Gtk.Entry:get_text()
).
- Returns: byte index into the entry layout text
set_attributes()
set_attributes (self, attrs:Pango.AttrList)
Sets a PangoAttrList; the attributes in the list are applied to theentry text.
- Since: 3.6
get_attributes()
get_attributes (self) -> Pango.AttrList or None
Gets the attribute list that was set on the entry usingGtk.Entry:set_attributes()
, if any.
Returns: the attribute list, or
None
if none was set.Since: 3.6
get_max_length()
get_max_length (self) -> int
Retrieves the maximum allowed length of the text inentry
. See Gtk.Entry:set_max_length()
.
This is equivalent to:
Gtk.EntryBuffer
*buffer;buffer = Gtk.Entry:get_buffer (entry);Gtk.Entry:buffer_get_max_length (buffer);
- Returns:
the maximum allowed number of charactersin
Gtk.Entry
, or 0 if there is no maximum.
get_visibility()
get_visibility (self) -> bool
Retrieves whether the text in entry
is visible. SeeGtk.Entry:set_visibility()
.
- Returns:
True
if the text is currently visible
set_completion()
set_completion (self, completion:Gtk.EntryCompletion=None)
Sets completion
to be the auxiliary completion object to use with entry
.All further configuration of the completion mechanism is done oncompletion
using the Gtk.EntryCompletion
API. Completion is disabled ifcompletion
is set to None
.
- Since: 2.4
get_completion()
get_completion (self) -> Gtk.EntryCompletion
Returns the auxiliary completion object currently in use by entry
.
Returns: The auxiliary completion object currentlyin use by
entry
.Since: 2.4
set_cursor_hadjustment()
set_cursor_hadjustment (self, adjustment:Gtk.Adjustment=None)
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. See `Gtk.ScrolledWindow: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.
- Since: 2.12
get_cursor_hadjustment()
get_cursor_hadjustment (self) -> Gtk.Adjustment or None
Retrieves the horizontal cursor adjustment for the entry. See Gtk.Entry:set_cursor_hadjustment()
.
Returns: the horizontal cursor adjustment, or
None
if none has been set.Since: 2.12
set_progress_fraction()
set_progress_fraction (self, fraction:float)
Causes the entry’s progress indicator to “fill in” the givenfraction of the bar. The fraction should be between 0.0 and 1.0,inclusive.
- Since: 2.16
get_progress_fraction()
get_progress_fraction (self) -> float
Returns the current fraction of the task that’s been completed.See Gtk.Entry:set_progress_fraction()
.
Returns: a fraction from 0.0 to 1.0
Since: 2.16
set_progress_pulse_step()
set_progress_pulse_step (self, fraction:float)
Sets the fraction of total entry width to move the progressbouncing block for each call to Gtk.Entry:progress_pulse()
.
- Since: 2.16
get_progress_pulse_step()
get_progress_pulse_step (self) -> float
Retrieves the pulse step set with Gtk.Entry:set_progress_pulse_step()
.
Returns: a fraction from 0.0 to 1.0
Since: 2.16
progress_pulse()
progress_pulse (self)
Indicates that some progress is made, but you don’t know how much.Causes the entry’s progress indicator to enter “activity mode,”where a block bounces back and forth. Each call toGtk.Entry:progress_pulse()
causes the block to move by a little bit(the amount of movement per pulse is determined byGtk.Entry:set_progress_pulse_step()
).
- Since: 2.16
im_context_filter_keypress()
im_context_filter_keypress (self, event:Gdk.EventKey) -> bool
Allow the Gtk.Entry
input method to internally handle key pressand release events. If this function returns True
, then no furtherprocessing should be done for this key event. SeeGtk.IMContext:filter_keypress`()`.
Note that you are expected to call this function from your handlerwhen overriding key event handling. This is needed in the case whenyou need to insert your own key handling between the input methodand the default key event handling of the `Gtk.Entry`.See
Gtk.TextView:reset_im_context()
for an example of use.
Returns:
True
if the input method handled the key event.Since: 2.22
reset_im_context()
reset_im_context (self)
Reset the input method context of the entry if needed. This can be necessary in the case where modifying the bufferwould confuse on-going input method behavior.
- Since: 2.22
get_tabs()
get_tabs (self) -> Pango.TabArray or None
Gets the tabstops that were set on the entry using Gtk.Entry:set_tabs()
, ifany.
Returns: the tabstops, or
None
if none was set.Since: 3.10
set_tabs()
set_tabs (self, tabs:Pango.TabArray)
Sets a PangoTabArray; the tabstops in the array are applied to the entrytext.
- Since: 3.10
set_icon_from_pixbuf()
set_icon_from_pixbuf (self, icon_pos:Gtk.EntryIconPosition, pixbuf:GdkPixbuf.Pixbuf=None)
Sets the icon shown in the specified position using a pixbuf.
If pixbuf
is None
, no icon will be shown in the specified position.
- Since: 2.16
set_icon_from_stock()
set_icon_from_stock (self, icon_pos:Gtk.EntryIconPosition, stock_id:str=None)
Gtk.Entry:set_icon_from_stock
has been deprecated since version 3.10 and should not be used in newly-written code.
Use Gtk.Entry:set_icon_from_icon_name()
instead.
Sets the icon shown in the entry at the specified position froma stock image.
If stock_id
is None
, no icon will be shown in the specified position.
- Since: 2.16
set_icon_from_icon_name()
set_icon_from_icon_name (self, icon_pos:Gtk.EntryIconPosition, icon_name:str=None)
Sets the icon shown in the entry at the specified positionfrom the current icon theme.
If the icon name isn’t known, a “broken image” icon will be displayedinstead.
If icon_name
is None
, no icon will be shown in the specified position.
- Since: 2.16
set_icon_from_gicon()
set_icon_from_gicon (self, icon_pos:Gtk.EntryIconPosition, icon:Gio.Icon=None)
Sets the icon shown in the entry at the specified positionfrom the current icon theme.If the icon isn’t known, a “broken image” icon will be displayedinstead.
If icon
is None
, no icon will be shown in the specified position.
- Since: 2.16
get_icon_storage_type()
get_icon_storage_type (self, icon_pos:Gtk.EntryIconPosition) -> Gtk.ImageType
Gets the type of representation being used by the iconto store image data. If the icon has no image data,the return value will be GTK_IMAGE_EMPTY
.
Returns: image representation being used
Since: 2.16
get_icon_pixbuf()
get_icon_pixbuf (self, icon_pos:Gtk.EntryIconPosition) -> GdkPixbuf.Pixbuf or None
Retrieves the image used for the icon. Unlike the other methods of setting and getting icon data, thismethod will work regardless of whether the icon was set using aGdkPixbuf, a GIcon, a stock item, or an icon name.
Returns: A GdkPixbuf, or
None
if no icon isset for this position.Since: 2.16
get_icon_stock()
get_icon_stock (self, icon_pos:Gtk.EntryIconPosition) -> str
Gtk.Entry:get_icon_stock
has been deprecated since version 3.10 and should not be used in newly-written code.
Use Gtk.Entry:get_icon_name()
instead.
Retrieves the stock id used for the icon, or None
if there isno icon or if the icon was set by some other method (e.g., bypixbuf, icon name or gicon).
Returns: A stock id, or
None
if no icon is set or if the iconwasn’t set from a stock idSince: 2.16
get_icon_name()
get_icon_name (self, icon_pos:Gtk.EntryIconPosition) -> str or None
Retrieves the icon name used for the icon, or None
if there isno icon or if the icon was set by some other method (e.g., bypixbuf, stock or gicon).
Returns: An icon name, or
None
if no icon is set or if the iconwasn’t set from an icon name.Since: 2.16
get_icon_gicon()
get_icon_gicon (self, icon_pos:Gtk.EntryIconPosition) -> Gio.Icon or None
Retrieves the GIcon used for the icon, or None
if there isno icon or if the icon was set by some other method (e.g., bystock, pixbuf, or icon name).
Returns: A GIcon, or
None
if no icon is setor if the icon is not a GIcon.Since: 2.16
set_icon_activatable()
set_icon_activatable (self, icon_pos:Gtk.EntryIconPosition, activatable:bool)
Sets whether the icon is activatable.
- Since: 2.16
get_icon_activatable()
get_icon_activatable (self, icon_pos:Gtk.EntryIconPosition) -> bool
Returns whether the icon is activatable.
Returns:
True
if the icon is activatable.Since: 2.16
set_icon_sensitive()
set_icon_sensitive (self, icon_pos:Gtk.EntryIconPosition, sensitive:bool)
Sets the sensitivity for the specified icon.
- Since: 2.16
get_icon_sensitive()
get_icon_sensitive (self, icon_pos:Gtk.EntryIconPosition) -> bool
Returns whether the icon appears sensitive or insensitive.
Returns:
True
if the icon is sensitive.Since: 2.16
get_icon_at_pos()
get_icon_at_pos (self, x:int, y:int) -> int
Finds the icon at the given position and return its index. Theposition’s coordinates are relative to the entry
’s top left corner.If x
, y
doesn’t lie inside an icon, -1 is returned.This function is intended for use in a “query-tooltip”signal handler.
Returns: the index of the icon at the given position, or -1
Since: 2.16
set_icon_tooltip_text()
set_icon_tooltip_text (self, icon_pos:Gtk.EntryIconPosition, tooltip:str=None)
Sets tooltip
as the contents of the tooltip for the iconat the specified position.
Use None
for tooltip
to remove an existing tooltip.
See also `Gtk.Widget:set_tooltip_text
()and
Gtk.Entry:set_icon_tooltip_markup()`.
- Since: 2.16
get_icon_tooltip_text()
get_icon_tooltip_text (self, icon_pos:Gtk.EntryIconPosition) -> str or None
Gets the contents of the tooltip on the icon at the specified position in entry
.
Returns: the tooltip text, or
None
. Free the returnedstring withg_free()
when done.Since: 2.16
set_icon_tooltip_markup()
set_icon_tooltip_markup (self, icon_pos:Gtk.EntryIconPosition, tooltip:str=None)
Sets tooltip
as the contents of the tooltip for the icon atthe specified position. tooltip
is assumed to be marked up withthe Pango text markup language.
Use None
for tooltip
to remove an existing tooltip.
See also `Gtk.Widget:set_tooltip_markup
()and
Gtk.Entry:set_icon_tooltip_text()`.
- Since: 2.16
get_icon_tooltip_markup()
get_icon_tooltip_markup (self, icon_pos:Gtk.EntryIconPosition) -> str or None
Gets the contents of the tooltip on the icon at the specified position in entry
.
Returns: the tooltip text, or
None
. Free the returnedstring withg_free()
when done.Since: 2.16
set_icon_drag_source()
set_icon_drag_source (self, icon_pos:Gtk.EntryIconPosition, target_list:Gtk.TargetList, actions:Gdk.DragAction)
Sets up the icon at the given position so that GTK+ will start a dragoperation when the user clicks and drags the icon.
To handle the drag operation, you need to connect to the usual“drag-data-get” (or possibly “drag-data-delete”)signal, and use Gtk.Entry:get_current_icon_drag_source()
inyour signal handler to find out if the drag was started froman icon.
By default, GTK+ uses the icon as the drag icon. You can use the “drag-begin” signal to set a different icon. Note that you have to use g_signal_connect_after()
to ensure that your signal handlergets executed after the default handler.
- Since: 2.16
get_current_icon_drag_source()
get_current_icon_drag_source (self) -> int
Returns the index of the icon which is the source of the currentDND operation, or -1. This function is meant to be used in a “drag-data-get”callback.
Returns: index of the icon which is the source of the currentDND operation, or -1.
Since: 2.16
get_icon_area()
get_icon_area (self, icon_pos:Gtk.EntryIconPosition) -> icon_area:Gdk.Rectangle
Gets the area where entry’s icon at icon_pos
is drawn.This function is useful when drawing something to theentry in a draw callback.
If the entry is not realized or has no icon at the given position,icon_area
is filled with zeros.
See also Gtk.Entry:get_text_area()
- Since: 3.0
set_input_purpose()
set_input_purpose (self, purpose:Gtk.InputPurpose)
Sets the “input-purpose” property whichcan be used by on-screen keyboards and other inputmethods to adjust their behaviour.
- Since: 3.6
get_input_purpose()
get_input_purpose (self) -> Gtk.InputPurpose
Gets the value of the “input-purpose” property.
- Since: 3.6
set_input_hints()
set_input_hints (self, hints:Gtk.InputHints)
Sets the “input-hints” property, whichallows input methods to fine-tune their behaviour.
- Since: 3.6
get_input_hints()
get_input_hints (self) -> Gtk.InputHints
Gets the value of the “input-hints” property.
- Since: 3.6
grab_focus_without_selecting()
grab_focus_without_selecting (self)
Causes entry
to have keyboard focus.
It behaves like `Gtk.Widget:grab_focus
()`,except that it doesn't select the contents of the entry.You only want to call this on some special entrieswhich the user usually doesn't want to replace all text in,such as search-as-you-type entries.
- Since: 3.16
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Entry(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("Entry")
self.connect("destroy", Gtk.main_quit)
entry = Gtk.Entry()
entry.set_placeholder_text("Entry text here...")
entry.connect("activate", self.on_entry_activated)
self.add(entry)
def on_entry_activated(self, entry):
print("Entry text: %s" % (entry.get_text()))
window = Entry()
window.show_all()
Gtk.main()