Hello!
I am making this flashcard game but whenever I clicked the correct or wrong button, I couldn’t see the feedback. Thank you
Steps to reproduce
if show_translation_button_clicked:
st.session_state.current_flashcard_index += 1
correct_clicked_button = st.button("Correct")
wrong_clicked_button = st.button("Wrong")
current_flashcard3 = current_flashcard["translation"]
st.write(current_flashcard3)
if correct_clicked_button:
print(st.write("You are correct!"))
if wrong_clicked_button:
print(st.write("You are wrong"))
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
I expected it to show the feedback whenever I click the button.
Actual behavior:
The feedback did not appear after I clicked the button.
Debug info
Streamlit version: Streamlit, version 1.25.0
Python version: (get it with $ python --version)
Using Conda? PipEnv? PyEnv? Pex?
OS version:
Browser version:
Requirements file
Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.
Links
Link to your GitHub repo:
Link to your deployed app:
Additional information
If needed, add any other context about the problem here.
Hi @Jun ,
Please try to put st.button("Show translation") in the if condition itself.
I have also faced the same and after some time I try this approach and it worked.
Hey @Jun,
In Streamlit Buttons return True only on the page load right after their click and immediately go back to False.
Simply, If their is a nested button then after clicking th first button the page get’s refreshed automatically. That is the reason why you are not able to see the feedback you want.
For solving this problem you can see the blog of streamlit in which they are explaining this perfectly.
If you want to nested button then you can see the code snippet given below for getting an idea how does the session state works for buttons in Streamlit.
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.