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.