2
import streamlit as st
import functions

list = functions.get_list()

def add_todo():
    todo = st.session_state["new_todo"] + "\n"
    list.append(todo)
    functions.write_list(list)


st.title("Simple To-Do app")
st.subheader("This is my todo app")
st.write("Increase your productivity")

for todo in list:
    st.checkbox(todo)

st.text_input(label = "", placeholder = "Add a new todo...",
              on_change=add_todo, key = 'new_todo')

When a widget is created, it's assigned an internal key based on its structure. Multiple widgets with an identical structure will result in the same internal key, which causes this error.

To fix this error, please pass a unique key argument to st.checkbox.

Traceback:

File "C:\Users\seraf\Desktop\Final project\web.py", line 17, in <module>
    st.checkbox(todo)
Sherif98
  • 21
  • 1

1 Answers1

1

This happens because you are trying to generate more than one checkbox with the same key value which is none. To solve this, every new checkbox should have a unique key value.
Example:
Assign a variable with an increment and set that as a key.
In the code below, unique_value will always increase in value which will make every new checkbox key defer from the rest of the checkboxes.

unique_value = 0
for todo in list:
    unique_value += 1
    st.checkbox(todo, key=f"todo{unique_value}")
        
Jamiu S.
  • 5,257
  • 5
  • 12
  • 34