Creating a Text Input

Creating a text input in zero-true is simple. Type:

import zero-true as zt
text_input=zt.TextInput(id='txt')

Run the cell in your notebook, and watch the text input appear below.

Text Input Settings and Values

Text inputs have a range of settings. For example you can add a label to your text input to clarify what you are asking of a user. To access the value they provide you simply use the “value” attribute on the component to access the string they typed:

print("The user just wrote "+text_input.value)

Text Input Use Cases

Text inputs are useful when you want the user to input a text value where the possible values are unknown or the number of options is too large to store in a list. For example in this use case we ask for a user’s name. Because we don’t have a list of users we can pull from we ask them to type it in themselves:

import zero_true as zt

#name input
name_input = zt.TextInput(id='txt_i',label='Write you name')

This works great for shorter texts. For longer texts we recommend that you use our TextArea component.

Customizing your Text Input

You can also add different colors and labels to your text input to make it to your liking. Feel free to check out the full range of options with the api reference for our text inputs.