Radio button in button click event

Hey. can anyone help me?

I have one radio button that appears if I click the โ€œGoโ€ button. Then if I want to change the option in radio button, it will back to default, meaning the radio button will not appear since it is in event โ€œGoโ€ button. It goes back to default because, it just appears if that click event hit. so how can I maintain the question along with the radio button and I can change the option with what I want. can you help?

Below is my code:

def display_question(question_list, question_index):
if question_index < len(question_list):
question = question_list[question_index][โ€œQuestionโ€]
options = question_list[question_index][โ€œOptionsโ€]
st.write(question)
# Display options as radio buttons
selectedoption = st.radio(โ€œOptions:โ€, options, key=f"question{question_index}")
st.session_state.selected_answers[question_index] = selected_option

if st.button(โ€œLetโ€™s go!โ€):
question_index = 0 # Index to keep track of the current question
st.session_state.question_index = question_index
display_question(st.session_state.question_list, question_index)

Hi @AmaniAli95,

Buttons will only be True for the script rerun resulting from their click. As soon as you click something else, the button goes back to False. Check out this guide for more explanation and examples: