if st.button(“START QUIZ”):
with col2:
st.selectbox(…)
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)
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.
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
else:
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
st.info('you chose option: ' + res)
sleep(1)
st.experimental_rerun()
else:
if st.button('start game'):
st.session_state['game_active'] = True
st.experimental_rerun()
Please @akshanshkmr have been trying to use session state but couldnt get it, this is my code
col1, col2= st.columns([3,5])
with col1:
st.header("RIDDLES FOR ORIJINAL HEROES")
img=Image.open('orijin.jpg')
st.image(img,use_column_width=True)
def quiz_start():
if 'START QUIZ' not in st.session_state:
st.session_state["START QUIZ"]=True
else:
st.session_state["START QUIZ"]=False
quiz=st.button("START QUIZ")
if quiz:
st.session_state["START QUIZ"]=True
with col2:
st.write("")
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"])