st.checkbox() in Streamlit

The checkbox is a boolean input widget that allows users to select or deselect an option. It returns True when checked and False when unchecked.

Syntax

st.checkbox(
    label,
    value=False,
    key=None,
    help=None,
    on_change=None,
    args=None,
    kwargs=None,
    *,
    disabled=False,
    label_visibility="visible",
    width="content"
)    

The function has the following parameters:

Example: Basic checkbox.

Python

# Import the Streamlit library
import streamlit as st

# Create a checkbox
show_text = st.checkbox("Show message")

# Display text only if checked
if show_text:
    st.write("✅ Checkbox is selected!")
else:
    st.write("⬜ Checkbox is not selected.")    

Output: When you tick the box, the message appears dynamically.

Checkbox in Streamlit