Text inputs
Text inputs enable users to enter free-form text data. You can use them for long and short-form entries.
Overview
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
- 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, wherea,b, andcare properties withrebindFalseanddis aStringProperty. Then when the rule is applied,textbecomes bound only tod. Ifa,b, orcchange,textstill remains bound tod. Furthermore, if any of them wereNonewhen the rule was initially evaluated, e.g.bwasNone; thentextis bound toband will not become bound todeven whenbis changed to not beNone.By setting
rebindtoTrue, however, the rule will be re-evaluated and all the properties rebound when that intermediate property changes. E.g. in the example above, wheneverbchanges or becomes notNoneif it wasNonebefore,textis evaluated again and becomes rebound tod. The overall result is thattextis now bound to all the properties amonga,b, orcthat haverebindset toTrue.- **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]
- class carbonkivy.uix.textinput.textinput.CTextInputTrailingIconButton(*args: Any, **kwargs: Any)[source]
Bases:
CButtonGhost