logo

Getting User Input

Widgets let users interact with your app. Each widget returns its current value.

import streamlit as st

name = st.text_input("What's your name?")
age = st.number_input("Your age", min_value=0, max_value=120)
agree = st.checkbox("I agree to the terms")

When a user changes a widget, Streamlit reruns your script with the new values.

More widgets:

# Slider
value = st.slider("Pick a number", 0, 100, 50)

# Dropdown
option = st.selectbox("Choose one", ["A", "B", "C"])

# Date
date = st.date_input("Select date")

Use the returned values in your logic:

if st.button("Click me"):
    st.write(f"Hello, {name}!")

Widgets are the core of interactivity in Streamlit.

I explain all widgets in my Streamlit course.