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"])
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.