class fields.TextEditor(Widget)

A TextEditor provides simple single-line text editing. Typed characters are inserted into the text, and characters are deleted using Delete or Backspace. Clicking on the text field gives it the keyboard focus and sets the insertion point. Pressing the Tab key moves to the next tabbable widget.

There is currently no support for selecting or copying and pasting text.

Constructor

TextEditor(width)
The width can be either an integer or a string. If an integer, it specifies the width in pixels; if a string, the widget is made just wide enough to contain the given text. The height is determined by the height of a line of text in the font in effect at construction time.

Theme Properties

fg_color
Colour in which to display the text and insertion bar.

sel_color
Colour in which to display selected text.

font
Font in which to display the text.

Properties

text
The current text, provided the get_text and set_text methods have not been overridden.

Attributes

upper
If true, text typed into the field is forced to upper case.
insertion_point
The current position of the insertion point. May be set to None to position it at the end of the text.
enter_action
A function of no arguments to be called when Return or Enter is pressed. If not specified, Return and Enter key events are passed to the parent widget.

escape_action
A function of no arguments to be called when Escape is pressed. If not specified, Escape key events are passed to the parent widget.

Abstract Methods

allow_char(c)
Called to determine whether typing the character c into the text editor should be allowed. The default implementation returns true for all characters.
get_text()
set_text(text)
Internally, the widget uses these methods to access the text being edited. By default they access text held in a private attribute. By overriding them, you can arrange for the widget to edit text being held somewhere else.
---