text_input widget in Streamlit

The text_input method is a text input widget in Streamlit that allows users to enter a single line of text.

It returns the string entered by the user.

Common Uses

Syntax

st.text_input(
    label,
    value="",
    max_chars=None,
    key=None,
    type="default",
    help=None,
    autocomplete=None,
    on_change=None,
    args=None,
    kwargs=None,
    *,
    placeholder=None,
    disabled=False,
    label_visibility="visible",
    icon=None,
    width="stretch"
)    

Important Parameters

Example: Basic Text Input

Python

# Import Streamlit
import streamlit as st

# Create input box
name = st.text_input("Enter your name")

# Display output
st.write(f"Hello, {name}!")    

Explanation

text_input widget in Streamlit

Example: With Default Value

Python

import streamlit as st

city = st.text_input("Enter city name:", value="New York")

st.write("You selected:", city)    

Example: Password Input

Python

import streamlit as st

password = st.text_input("Enter your password:", type="password")

st.write("Password length:", len(password))    

Example: With Placeholder

Python

import streamlit as st

email = st.text_input(
    "Enter your email:",
    placeholder="example@example.com"
)

st.write("Your email is:", email)