without adding time.sleep() inside the buttons, it works just fine.
However, including time.sleep() within the buttons disrupts the intended behavior of nested buttons working independently.
This causes an issue where toggling a nested button triggers its parent button as well, compromising the individual functionality of the nested buttons.
if "father" not in st.session_state:
st.session_state["father"] = False
if "child" not in st.session_state:
st.session_state["child"] = False
if "grandchild" not in st.session_state:
st.session_state["grandchild"] = False
st.session_state["child"] = False
if "donkey" not in st.session_state:
st.session_state["donkey"] = False
if st.button("FATHER"):
st.session_state["father"] = not st.session_state["father"]
if st.session_state["father"]:
st.write("FATHER HAS APPEARED")
if st.button("CHILD"):
st.session_state["child"] = not st.session_state["child"]
if st.session_state["father"] and st.session_state["child"]:
# time.sleep(2)
st.write("CHILD HAS APPEARED")
if st.button("GRANDCHILD"):
st.session_state["grandchild"] = not st.session_state["grandchild"]
if (
st.session_state["father"]
and st.session_state["child"]
and st.session_state["grandchild"]
):
# time.sleep(2)
st.write("GRANDCHILD HAS APPEARED")
if st.button("DONKEY"):
st.session_state["donkey"] = not st.session_state["donkey"]
if (
st.session_state["father"]
and st.session_state["child"]
and st.session_state["grandchild"]
and st.session_state["donkey"]
):
st.write("GO BACK!")
st.write(
f"""
## Session state:
{st.session_state["father"]=}
{st.session_state["child"]=}
{st.session_state["grandchild"]=}
{st.session_state["donkey"]=}
"""
)