A widget key is the identifier Streamlit uses to tell one widget from another. Streamlit usually generates it from a widget’s characteristics. Two otherwise identical buttons—for example, two buttons labeled Delete in a task list—can therefore produce the same key and trigger an error. Give each button a distinct key to make the widgets distinguishable. section 4.2.1
One Delete button per task
Loop over the tasks with enumerate(task_list) to obtain both the task and its index. Then pass key=f"delete_{idx}" to each Delete button. The visible labels stay the same, while the keys become delete_0, delete_1, and so on. Apply the same pattern to task checkboxes if they need explicit keys. section 4.2.1
for idx, task in enumerate(task_list):
task_col, delete_col = st.columns([0.8, 0.2])
task_col.checkbox(task.name, task.is_done)
if delete_col.button("Delete", key=f"delete_{idx}"):
pass
See how the loop gives each identically labeled Delete button a unique key. section 4.2.1
A manually keyed input also exposes its value through st.session_state. For a selectbox with key="select_dim", read or set st.session_state["select_dim"]. To choose its value programmatically, set the session-state entry before the widget runs; do not render the widget first and then overwrite its value. section 7.6.2
Keys can also identify which dashboard inputs belong in a shareable URL. Prefix selected widget keys with w:, load matching query parameters into st.session_state before rendering, and write those widget values back to st.query_params after rendering. Set URL-derived values only when their keys are not already in session state, so later user selections remain changeable. Values such as dates and lists need conversion when moving between widget values and URL strings. section 7.6.3 section 7.6.2
A unique key identifies the clicked button; it does not by itself refresh display logic that already ran. If a deleted task still appears, step through the rerun: the task and button may have been displayed before the deletion changed the list. section 4.5.3
