St.selectbox dissapearing

if st.button(“START QUIZ”):
with col2:

The above code is what am currently using, but when i click on the “START QUIZ button”, it displays the QUIZES but when i choose an option, the whole quizzes disappear and i have to click on START QUIZ again.


I tried, when selectbox under a button will appear like you described.
maybe you can try this to replace:

import streamlit as st
with st.expander("click me to make a choose"):
	choose = st.selectbox("please select one option",("A","B","C"))
	if choose:
		st.write("Your choose option is" + " " + choose)

1 Like

Thanks @BeyondMyself , I understand above logic but this doesnt solve my problem, The problem is my app keep refreshing itself immediately i select an option from the select box

yes, I tried your design, when button is clicked, and change selectbox option, selectbox will disappear.
So I suggest you use st.expander to replace st.button as a temp solution.

1 Like

Okay thanks…I will try this method…@BeyondMyself

Hi @kareemrasheed89 ,

The ideal solution to your problem would be to use st.form with session state.


1 Like

Can you explain with a code @akshanshkmr

Sure, I’ll try to send one by tomorrow morning

1 Like

@akshanshkmr any update pls

Hi @kareemrasheed89,

Apologies for the delay, you can do something like this

from time import sleep

def is_game_active():
    if 'game_active' in st.session_state.keys() and st.session_state['game_active']:
        return True
        return False

if is_game_active():
    # TODO: implement logic to fetch random_question (and options) on each rerun
    res = st.selectbox('random_question', ['a','b','c','d'])
    if st.button('confirm'):
        st.session_state['random_question'] = res # saves answers for each random question in sesion state for future reference'you chose option: ' + res)
    if st.button('start game'):
        st.session_state['game_active'] = True

Feel free to experiment on Streamlit Playground (


1 Like

Many thanks @akshanshkmr , I just saw your message, I will try and get back

Please @akshanshkmr have been trying to use session state but couldnt get it, this is my code :point_down:

col1, col2= st.columns([3,5])
with col1:
    st.header("RIDDLES FOR ORIJINAL HEROES")'orijin.jpg')
    def quiz_start():
        if 'START QUIZ' not in st.session_state:
            st.session_state["START QUIZ"]=True
            st.session_state["START QUIZ"]=False
    quiz=st.button("START QUIZ")
    if quiz:
        st.session_state["START QUIZ"]=True
        with col2:
            QUIZ1=st.selectbox("How do you party?",["",'With Friends','With Everyone',])
            QUIZ2=st.selectbox("You see a burning house, what do you do?",["","Run into the house, to help","Call for help"])

            QUIZ3=st.selectbox("Which of these best describes you?",["","Loud and Bold","Silent and courageous"])

            QUIZ4=st.selectbox("What's your first response to any challenge?",["","Tactical and careful considerations","Spontaneous and quick to act"])

            QUIZ5=st.selectbox("What is your gender?",["","Male","Female"])