gtk.Entry
Prev | The gtk Class Reference | Next

## gtk.Entry

gtk.Entry — a single line text entry field.

## Synopsis

    class gtk.Entry(gtk.Widget, gtk.Editable, gtk.CellEditable):
        gtk.Entry(max=0)
        def set_visibility(visible)
        def get_visibility()
        def set_invisible_char(ch)
        def get_invisible_char()
        def set_has_frame(setting)
        def get_has_frame()
        def set_max_length(max)
        def get_max_length()
        def set_activates_default(setting)
        def get_activates_default()
        def set_width_chars(n_chars)
        def get_width_chars()
        def set_text(text)
        def get_text()
        def get_layout()
        def get_layout_offsets()
        def set_alignment(xalign)
        def get_alignment()
        def set_completion(width_chars)
        def get_completion()
        def set_inner_border(border)
        def get_inner_border()

## Ancestry

    +-- gobject.GObject
      +-- gtk.Object
        +-- gtk.Widget
          +-- gtk.Entry (implements gtk.Editable, gtk.CellEditable)

## gtk.Entry Properties

gtk.Object Properties

gtk.Widget Properties

"activates-default" | Read/Write | If `TRUE` activate the default widget (such as the default button in a dialog) when Enter is pressed. Default value: `FALSE`.
"cursor-position" | Read | The current position of the insertion cursor as a character index. Allowed values: [0,65535]. Default value: 0
"editable" | Read/Write | If `TRUE` the entry contents can be edited. Default value: `TRUE`.
"has-frame" | Read/Write | If `FALSE` removes outside bevel from entry. Default value: `TRUE`.
"inner-border" | Read/Write | The text area's border between the text and the frame as a gtkBorder. Available in GTK+ 2.10.
"invisible-char" | Read/Write | The character to use when masking entry contents (when "visibility" is `FALSE`). Default value: '*'.
"max-length" | Read/Write | The maximum number of characters for this entry. Zero if no maximum. Allowed values: [0,65535] Default value: 0.
"scroll-offset" | Read | The number of pixels of the entry scrolled off the screen to the left. Allowed values: >= 0 Default value: 0.
"selection-bound" | Read | The position of the opposite end of the selection from the cursor as a character index. Allowed values: [0,65535] Default value: 0.
"text" | Read/Write | The contents of the entry. Default value: "".
"truncate-multiline" | Read/Write | If `TRUE`, pasted multi-line text is truncated to the first line. Default value: `FALSE`. Available in GTK+ 2.10 and above.
"visibility" | Read/Write | If `FALSE` displays the "invisible char" instead of the actual text (e.g. password mode). Default value: `TRUE`.
"width-chars" | Read/Write | The number of characters to leave space for in the entry. Allowed values: >= -1. Default value: -1.
"xalign" | Read/Write | The horizontal alignment ranging from 0.0 to 1.0 representing the fraction of freespace to the left (right for RTL layouts) of the text. Available in GTK+ 2.4 and above.

## gtk.Entry Style Properties

gtk.Widget Style Properties

"inner-border" | Read | Sets the text area's border between the text and the frame This property is available in GTK+ 2.10 and above.

## gtk.Entry Signal Prototypes

gobject.GObject Signal Prototypes

gtk.Object Signal Prototypes

gtk.Widget Signal Prototypes

gtk.Editable Signal Prototypes

gtk.CellEditable Signal Prototypes

"activate" | `def callback(`entry`, `user_param1`, `...`)`
"backspace | `def callback(`entry`, `user_param1`, `...`)`
"copy-clipboard" | `def callback(`entry`, `user_param1`, `...`)`
"cut-clipboard" | `def callback(`entry`, `user_param1`, `...`)`
"delete-from-cursor" | `def callback(`entry`, `delete_type`, `count`, `user_param1`, `...`)`
"insert-at-cursor" | `def callback(`entry`, `string`, `user_param1`, `...`)`
"move-cursor" | `def callback(`entry`, `step_size`, `count`, `extend_selection`, `user_param1`, `...`)`
"paste-clipboard" | `def callback(`entry`, `user_param1`, `...`)`
"populate-popup" | `def callback(`entry`, `menu`, `user_param1`, `...`)`
"toggle-overwrite" | `def callback(`entry`, `user_param1`, `...`)`

## 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.

## Constructor

        gtk.Entry(max=0)

`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 limited to the range 0-65536.
Returns : | a new `gtk.Entry`.

Creates a new `gtk.Entry` widget with the maximum length specified by `max`.

## Methods

### gtk.Entry.set_visibility

        def set_visibility(visible)

`visible` : | If FALSE the contents are obscured using the "invisible-char"

The `set_visibility`() method sets the "visibility" property to the value of `visible`. If visible is `TRUE` the contents of the entry are displayed as plain text. If visible is `FALSE`, the contents are obscured by replacing the characters with the invisible character (specified by the "invisible-char" property). The characters will also be obscured when the text in the entry widget is copied elsewhere. The default invisible char is the asterisk '*', but it can be changed with `set_invisible_char`().

### gtk.Entry.get_visibility

        def get_visibility()

Returns : | `TRUE` if the text is currently visible

The `get_visibility`() method retrieves the value of the "visibility" property that determines whether the text in `entry` is visible. See `set_visibility`().

### gtk.Entry.set_invisible_char

        def set_invisible_char(ch)

`ch` : | a Unicode character

The `set_invisible_char`() method sets the "invisible-char" property with the value of `ch`. The "invisible-char" is 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. The default invisible character is an asterisk ('*'). If you set the invisible character to 0, then the user will get no feedback at all; there will be no text on the screen as they type.

### gtk.Entry.get_invisible_char

        def get_invisible_char()

Returns : | the current invisible char, or 0, if the entry does not show invisible text at all.

The get_invisible_char() method retrieves the value of the "invisible-char" property. The "invisible-char" is the character displayed in place of the real characters for entries with visibility set to `FALSE`. See `set_invisible_char`().

### gtk.Entry.set_has_frame

        def set_has_frame(setting)

`setting` : | If TRUE the entry is displayed with a beveled frame around it.

The `set_has_frame`() method sets the "has-frame" property to the value of `setting`. If `setting` is `TRUE` the entry is displayed with a beveled frame around it.

### gtk.Entry.get_has_frame

        def get_has_frame()

Returns : | whether the entry has a beveled frame

The `get_has_frame`() method gets the value of the "has-frame" property. If "has-frame" is `TRUE` the entry will be displayed with a beveled frame around it.

### gtk.Entry.set_max_length

        def 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.

The `set_max_length`() method sets the "max-length" property to the value of `max`. The "max-length" property 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. If max is 0 then there is no maximum length (other than 65536).

### gtk.Entry.get_max_length

        def get_max_length()

Returns : | the maximum allowed number of characters in `gtk.Entry`, or 0 if there is no maximum.

The `get_max_length`() method retrieves the value of the "max-length" property that specifies the maximum allowed length of the text in the entry. See `set_max_length`().

### gtk.Entry.set_activates_default

        def set_activates_default(setting)

`setting` : | If `TRUE` activate the window's default widget on an Enter key press

The `set_activates_default`() method sets the "activates-default" property to the value of `setting`. If `setting` is `TRUE`, pressing the Enter key 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 `TRUE`, the entry calls `gtk.Window.activate_default`() on the window containing the entry, in the default handler for the "activate" signal.)

### gtk.Entry.get_activates_default

        def get_activates_default()

Returns : | `TRUE` if the entry will activate the default widget

The `get_activates_default`() method retrieves the value of the "activates-default" property which is set by `set_activates_default`(). If "activates-default" is `TRUE` pressing the Enter key in the entry will activate the default widget for the window containing the entry.

### gtk.Entry.set_width_chars

        def set_width_chars(n_chars)

`n_chars` : | width in chars

The `set_width_chars`() method sets the "width-chars" property to the value of `n_char`. Setting the "width-chars" property changes the size request of the entry to be about the right size for `n_chars` characters. Note that it only 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.

### gtk.Entry.get_width_chars

        def get_width_chars()

Returns : | number of chars to request space for, or negative if unset

The `get_width_chars`() method gets the value of the "width-chars" property which is set by the `set_width_chars`() method.

### gtk.Entry.set_text

        def set_text(text)

`text` : | a string to use as the new contents of the entry

The `set_text`() method sets the "text" property to the value of `text`. The string in `text` replaces the current contents of the entry.

### gtk.Entry.get_text

        def get_text()

Returns : | the contents of the entry as a string

The `get_text`() method returns the value of the "text" property which is a string containing the contents of the entry.

### gtk.Entry.get_layout

        def get_layout()

Returns : | the `pango.Layout` for this entry

The `get_layout`() method 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 `get_layout_offsets`().

### gtk.Entry.get_layout_offsets

        def get_layout_offsets()

Returns : | a tuple containing the X and Y offsets of the pango layout

The `get_layout_offsets`() method obtains the position of the `pango.Layout` used to render text in the entry, in widget coordinates and returns it as a tuple. This method is used 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. It is 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.

### gtk.Entry.set_alignment

        def set_alignment(xalign)

`xalign` : | The horizontal alignment ranging from 0.0 to 1.0 representing the freespace to the left (right for RTL layouts) of the text.

### Note

This method is available in PyGTK 2.4 and above.

The `set_alignment`() method sets the "xalign" property to the value of `xalign`. The alignment controls the horizontal positioning of the contents when the displayed text is shorter than the width of the entry. The value of `xalign` is the fraction of freespace to the left (right in RTL layouts) of the text.

### gtk.Entry.get_alignment

        def get_alignment()

Returns : | The horizontal alignment ranging from 0.0 to 1.0 representing the freespace to the left (right for RTL layouts) of the text.

### Note

This method is available in PyGTK 2.4 and above.

The `get_alignment`() method returns the value of the "xalign" property which is the fraction of freespace (if any) to the left (right in RTL layouts) of the text.

### gtk.Entry.set_completion

        def set_completion(completion)

`completion` : | a `gtk.EntryCompletion`

### Note

This method is available in PyGTK 2.4 and above.

The `set_completion`() method sets the `gtk.EntryCompletion` specified by `completion` to be the auxiliary completion object to use with the entry. All further configuration of the completion mechanism is done using `completion` and the `gtk.EntryCompletion` methods.

### gtk.Entry.get_completion

        def get_completion()

Returns : | the auxiliary completion object

### Note

This method is available in PyGTK 2.4 and above.

The `get_completion`() method returns the `gtk.EntryCompletion` object currently in use by the entry.

### gtk.Entry.set_inner_border

        def set_inner_border(border)

`border` : | a `gtk.Border`, or `None`

### Note

This method is available in PyGTK 2.10 and above.

The `set_inner_border`() method sets the entry's "inner-border" property to the value specified by `border`, or clears it if `None` 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.

### gtk.Entry.get_inner_border

        def get_inner_border()

Returns : | the entry's `gtk.Border`, or `None` if none was set.

### Note

This method is available in PyGTK 2.10 and above.

The `get_inner_border`() method returns the value of the entry's "inner-border" property. See `set_inner_border`() for more information.

## Signals

### The "activate" gtk.Entry Signal

        def callback(entry, user_param1, ...)

`entry` : | the entry that received the signal
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "activate" signal is emitted when the entry is activated either by user action (pressing the Enter key) or programmatically with the `gtk.Widget.activate`() method

### The "backspace" gtk.Entry Signal

        def callback(entry, user_param1, ...)

`entry` : | the object which received the signal.
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "backspace" signal is emitted when the Backspace key is entered from the keyboard.

### The "copy-clipboard" gtk.Entry Signal

        def callback(entry, user_param1, ...)

`entry` : | the entry that received the signal
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "copy-clipboard" signal is emitted when the selection text in the entry is copied to the clipboard.

### The "cut-clipboard" gtk.Entry Signal

        def callback(entry, user_param1, ...)

`entry` : | the entry that received the signal
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "cut-clipboard" signal is emitted when the selection in the entry is cut (removed from the entry) and placed in the clipboard.

### The "delete-from-cursor" gtk.Entry Signal

        def callback(entry, delete_type, count, user_param1, ...)

`entry` : | the entry that received the signal
`delete_type` : | the type of deletion
`count` : | the number of deletions of the type to perform
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "delete-from-cursor" signal is emitted when the a deletion from the cursor i.e. removal o text at the cursor position, either before it (negative `count`) or after it (positive `count`). The value of `delete_type` can be one of:

- gtk.DELETE_CHARS
- gtk.DELETE_WORD_ENDS
- gtk.DELETE_WORDS
- gtk.DELETE_DISPLAY_LINES
- gtk.DELETE_DISPLAY_LINE_ENDS
- gtk.DELETE_PARAGRAPH_ENDS
- gtk.DELETE_PARAGRAPHS
- gtk.DELETE_WHITESPACE

### The "insert-at-cursor" gtk.Entry Signal

        def callback(entry, string, user_param1, ...)

`entry` : | the entry that received the signal
`string` : | the text being inserted in the entry
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "insert-at-cursor" signal is emitted when text is being inserted in the entry.

### The "move-cursor" gtk.Entry Signal

        def callback(entry, step, count, extend_selection, user_param1, ...)

`entry` : | the entry that received the signal
`step` : | the size of the step to move the cursor
`count` : | the number of steps to move the cursor
`extend_selection` : | if TRUE extend the selection as well as moving the cursor
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "move-cursor" signal is emitted when the cursor is being moved by `count` steps of size `step`. If `extend_selection` is `TRUE` the selection is extended as the cursor is being moved. The value of `step` can be one of:

- gtk.MOVEMENT_LOGICAL_POSITIONS
- gtk.MOVEMENT_VISUAL_POSITIONS
- gtk.MOVEMENT_WORDS
- gtk.MOVEMENT_DISPLAY_LINES
- gtk.MOVEMENT_DISPLAY_LINE_ENDS
- gtk.MOVEMENT_PARAGRAPH_ENDS
- gtk.MOVEMENT_PARAGRAPHS
- gtk.MOVEMENT_PAGES
- gtk.MOVEMENT_BUFFER_ENDS

### The "paste-clipboard" gtk.Entry Signal

        def callback(entry, user_param1, ...)

`entry` : | the entry that received the signal
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "paste-clipboard" signal is emitted when the contents of the clipboard are pasted into the entry.

### The "populate-popup" gtk.Entry Signal

        def callback(entry, menu, user_param1, ...)

`entry` : | the entry that received the signal
`menu` : | the menu that needs populating
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "populate-popup" signal is emitted when the `menu` needs populating.

### The "toggle-overwrite" gtk.Entry Signal

        def callback(entry, user_param1, ...)

`entry` : | the entry that received the signal
`user_param1` : | the first user parameter (if any) specified with the `connect`() method
`...` : | additional user parameters (if any)

The "toggle-overwrite" signal is emitted when the internal entry attribute "overwrite_mode" is toggled by pressing the Insert key.

Prev | Up | Next
gtk.Editable | Home | gtk.EntryCompletion