text_input(label: str, placeholder: str = "", size: float = 1.0) -> str

The text_input function adds an interactive text box to capture user input in your app. It maintains state between reruns, making it perfect for forms and interactive applications.

Parameters

  • label (str): The label displayed next to the text input, indicating its purpose. Also used to generate a consistent ID for state management.
  • placeholder (str): (Optional) Placeholder text shown when the input is empty. Helps guide users on what to enter.
  • size (float): (Optional) The width of the component in a row. Defaults to 1.0 (full row). See the Layout Guide for details.

Returns

  • str: The current value of the text input. Empty string if no input has been provided.

Usage Example

Here’s an example of how to use text inputs in your app:

from preswald import text_input, text, alert

# Basic text input
name = text_input(label="Enter your name", placeholder="John Doe")

# Using text input in a form
email = text_input(label="Email", placeholder="user@example.com")
password = text_input(label="Password", placeholder="Enter password")

if name and email and password:
    alert(f"Welcome {name}!", level="success")

Key Features

  1. Customizable Label: Set the label to distinguish between different text_inputs.
  2. Adjustable Placeholder: Control the look of the textboxes for better UI/UX.

Why Use text_input?

Text Inputs provide a way to create get end-user text input in the data app.

Was this page helpful?