Multipage app - how to change widget value on entrypoint page

I have a multipage app with a navigation sidebar that links to 3 other pages I can navigate to. The entrypoint file has a sidebar with the navigation pages in a sidebar which also has a checkbox widget. I set the value of this widget when this widget gets created to True .

When I navigate to one of the navigation pages, I would like to change the above widget value to False in the entrypoint file. I tried to do this by creating a session_state variable in the entrypoint file and using it to populate the widget’s value. When I try to change the value of this variable session_state on the navigated page (hoping it will change the widget value), I get an error.

Code in entrypoint file:

if "one" not in st.session_state:
    st.session_state["one"] = True
chk = st.checkbox("My Options", value=st.session_state["one"], key='one')

File I navigate to has this code:

if "one" in st.session_state:
    st.session_state["one"] = False    
    st.write("st.session_state['one'] has been changed to False")

Error I get:
StreamlitAPIException: st.session_state.one cannot be modified after the widget with key one is instantiated.

Please tell me how I can get the desired effect.

The logic look fine, the error is the key ‘one’ in the checkbox (this is why you got the error cannot be modified after te widget with key ‘one’ is instantiated):

You should changed it by something else :

chk = st.checkbox("My Options", value=st.session_state["one"], key='checkbox_one')

@Faltawer Thanks, I tried it. It doesn’t work. I don’t get the APIException error I was getting earlier but the widget doesn’t get updated either. My guess is that the issue is that in multipage apps widgets retain their state from page to page and by changing the session state alone is not enough, I have to force a refresh of the widgets on entrypoint page. Don’t know how?

We progress !
You should share a bit more of your code : here it’s difficult to reproduce the code. I don’t have any problem with different page/widget/session_state.