A single line text entry field
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.
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
<gtk-entry>
) (text mchars
)Sets the text in the widget to the given value, replacing the current contents.
- entry
- a
<gtk-entry>
.- text
- the new text.
<gtk-entry>
) ⇒ (ret mchars
)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.
<gtk-entry>
) (visible bool
)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.
<gtk-entry>
) (ch unsigned-int32
)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
<gtk-entry>
) (max int
)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.
<gtk-entry>
) ⇒ (ret bool
)Retrieves the value set by
gtk-entry-set-activates-default
.
- entry
- a
<gtk-entry>
- ret
- ‘
#t
’ if the entry will activate the default widget
<gtk-entry>
) ⇒ (ret bool
)Gets the value set by
gtk-entry-set-has-frame
.
- entry
- a
<gtk-entry>
- ret
- whether the entry has a beveled frame
<gtk-entry>
) ⇒ (ret <gtk-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
<gtk-entry>
) ⇒ (ret int
)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
<gtk-entry>
) (setting bool
)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 callsgtk-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
<gtk-entry>
) (setting bool
)Sets whether the entry has a beveled frame around it.
- entry
- a
<gtk-entry>
- setting
- new value
<gtk-entry>
) (border <gtk-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
<gtk-entry>
) (n_chars int
)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
<gtk-entry>
) ⇒ (ret unsigned-int32
)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.
<gtk-entry>
) (xalign float
)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
<gtk-entry>
) ⇒ (ret float
)Gets the value set by
gtk-entry-set-alignment
.
- entry
- a
<gtk-entry>
- ret
- the alignment
Since 2.4
<gtk-entry>
) ⇒ (ret <pango-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 withgtk-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
andgtk-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
<gtk-entry>
) ⇒ (x int
) (y int
)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 usingpango-pixels
or<pango-scale>
.Keep in mind that the layout text may contain a preedit string, so
gtk-entry-layout-index-to-text-index
andgtk-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
’
<gtk-entry>
) ⇒ (ret int
)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.
<gtk-entry>
) ⇒ (ret bool
)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
<gtk-entry>
) (completion <gtk-entry-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