Text inputs

Text inputs enable users to enter free-form text data. You can use them for long and short-form entries.

Overview

../../_images/carbondesigntextinputs.png

Text inputs enable users to enter free-form text data. The type of text field used should reflect the length of the content you expect the user to enter. The default text input is for short, one-line content, whereas text area is for longer, multi-line entries.

Only default variant of CTextInput is available.

Live demo

Click below text inputs to test user interactivity.

Note

This live demo contains only a preview of functionality and styles available for this component. Actual widgets may not show the exact same behavior but similar to expected.

CTextInputLayout:

    CTextInput:
        hint_text: "Placeholder text"

    CTextInputLabel:
        text: "Label text"

    CTextInputHelperText:
        text: "Helper text"

Example

Run below code for a full-fledged running example.

from kivy.clock import Clock
from kivy.core.window import Window


def set_softinput(*args) -> None:
    Window.keyboard_anim_args = {"d": 0.2, "t": "in_out_expo"}
    Window.softinput_mode = "below_target"


Window.on_restore(Clock.schedule_once(set_softinput, 0.1))

appkv = """
CScreen:

    CTextInputLayout:
        pos_hint: {"center_x": 0.5, "center_y": 0.5}
        size_hint_x: None
        width: dp(300)

        CTextInput:
            hint_text: "Placeholder text"

        CTextInputLabel:
            text: "Label text"

        CTextInputHelperText:
            text: "Helper text"

        CTextInputTrailingIconButton:
            icon: "error"
            spacing: 0

"""

from kivy.lang import Builder

from carbonkivy.app import CarbonApp
from carbonkivy.uix.screen import CScreen


class myapp(CarbonApp):
    def __init__(self, *args, **kwargs):
        super(myapp, self).__init__(*args, **kwargs)

    def build(self) -> CScreen:
        screen = Builder.load_string(appkv)
        return screen


if __name__ == "__main__":
    myapp().run()

API

class carbonkivy.uix.textinput.textinput.CTextInput(*args: Any, **kwargs: Any)[source]

Bases: AdaptiveBehavior, TextInput, DeclarativeBehavior

on_parent(*args) None[source]
on_password(*args) None[source]
class carbonkivy.uix.textinput.textinput.CTextInputHelperText(*args: Any, **kwargs: Any)[source]

Bases: CLabel

class carbonkivy.uix.textinput.textinput.CTextInputLabel(*args: Any, **kwargs: Any)[source]

Bases: CLabel

class carbonkivy.uix.textinput.textinput.CTextInputLayout(*args: Any, **kwargs: Any)[source]

Bases: AdaptiveBehavior, BackgroundColorBehaviorRectangular, StateFocusBehavior, RelativeLayout, DeclarativeBehavior, HierarchicalLayerBehavior, HoverBehavior

ctextinput_area

ObjectProperty(defaultvalue=None, rebind=False, **kw) Property that represents a Python object.

Parameters:
defaultvalue: object type

Specifies the default value of the property.

rebind: bool, defaults to False

Whether kv rules using this object as an intermediate attribute in a kv rule, will update the bound property when this object changes.

That is the standard behavior is that if there’s a kv rule text: self.a.b.c.d, where a, b, and c are properties with rebind False and d is a StringProperty. Then when the rule is applied, text becomes bound only to d. If a, b, or c change, text still remains bound to d. Furthermore, if any of them were None when the rule was initially evaluated, e.g. b was None; then text is bound to b and will not become bound to d even when b is changed to not be None.

By setting rebind to True, however, the rule will be re-evaluated and all the properties rebound when that intermediate property changes. E.g. in the example above, whenever b changes or becomes not None if it was None before, text is evaluated again and becomes rebound to d. The overall result is that text is now bound to all the properties among a, b, or c that have rebind set to True.

**kwargs: a list of keyword arguments
baseclass

If kwargs includes a baseclass argument, this value will be used for validation: isinstance(value, kwargs[‘baseclass’]).

Warning

To mark the property as changed, you must reassign a new python object.

Changed in version 1.9.0: rebind has been introduced.

Changed in version 1.7.0: baseclass parameter added.

on_kv_post(*args)[source]
update_specs(*args) None[source]
class carbonkivy.uix.textinput.textinput.CTextInputTrailingIconButton(*args: Any, **kwargs: Any)[source]

Bases: CButtonGhost