Text Input

macOS

GTK+

Windows

iOS

Android

Django

y

y

y

y

y

y

The text input widget is a simple input field for user entry of text data.

../../../_images/TextInput.jpeg

Usage

import toga

input = toga.TextInput(placeholder='enter name here')

Reference

class toga.widgets.textinput.TextInput(id=None, style=None, factory=None, initial=None, placeholder=None, readonly=False, on_change=None, on_gain_focus=None, on_lose_focus=None, validators=None)

A widget get user input.

Parameters
  • id (str) – An identifier for this widget.

  • style (Style) – An optional style object. If no style is provided then a new one will be created for the widget.

  • factory (module) – A python module that is capable to return a implementation of this class with the same name. (optional & normally not needed)

  • initial (str) – The initial text for the input.

  • placeholder (str) – If no input is present this text is shown.

  • readonly (bool) – Whether a user can write into the text input, defaults to False.

  • on_change (callable) – Method to be called when text is changed in text box

  • validators (list) – list of validators to run on the value of the text box. Should return None is value is valid and an error message if not.

  • on_change – The handler to invoke when the text changes.

  • on_gain_focus (callable) – Function to execute when get focused.

  • on_lose_focus (callable) – Function to execute when lose focus.

MIN_WIDTH = 100
add(*children)

Add nodes as children of this one. If a node already has a different parent, it will be moved over. This does nothing if a node already is a child of this node.

Parameters

children – Nodes to add as children of this node.

Raises

ValueError – If this node is a leaf, and cannot have children.

property app

The App to which this widget belongs. On setting the app we also iterate over all children of this widget and set them to the same app.

Returns

The toga.App to which this widget belongs.

Raises

ValueError – If the widget is already associated with another app.

property can_have_children

Determine if the node can have children.

This does not resolve whether there actually are any children; it only confirms whether children are theoretically allowed.

property children

The children of this node. This always returns a list, even if the node is a leaf and cannot have children.

Returns

A list of the children for this widget.

clear()

Clears the text of the widget

property enabled
focus()
property id

The node identifier. This id can be used to target styling directives

Returns

The widgets identifier as a str.

insert(index, child)

Insert a node as a child of this one. If the node already has a different parent, it will be moved over. This does nothing if the node already is a child of this node.

Parameters
  • index – Position of child node.

  • child – A node to insert as a child of this node.

Raises

ValueError – If this node is a leaf, and cannot have children.

property on_change

The handler to invoke when the value changes

Returns

The function callable that is called on a content change.

property on_gain_focus

The handler to invoke when the widget get focus.

Returns

The function callable that is called on widget focus gain.

property on_lose_focus

The handler to invoke when the widget lose focus.

Returns

The function callable that is called on widget focus loss.

property parent

The parent of this node.

Returns

The parent of this node. Returns None if this node is the root node.

property placeholder

The placeholder text.

Returns

The placeholder text as a str.

property readonly

Whether a user can write into the text input

Returns

True if only read is possible. False if read and write is possible.

refresh()

Refresh the layout and appearance of the tree this node is contained in.

refresh_sublayouts()
remove(*children)

Remove child nodes of this node. This does nothing if a given node is not a child of this node.

Parameters

children – Child nodes to remove.

Raises

ValueError – If this node is a leaf, and cannot have children.

property root

The root of the tree containing this node.

Returns

The root node. Returns self if this node is the root node.

validate()
property validators
property value

The value of the text input field

Returns

The current text of the widget as a str.

property window

The Window to which this widget belongs. On setting the window, we automatically update all children of this widget to belong to the same window.

Returns

The toga.Window to which the widget belongs.