A callback is a function supplied to another component for execution in response to a later event. In Streamlit, a button callback runs before the page reruns, so state changes are already reflected without manually calling st.rerun(). section 9.6.2
Advance a trivia game
A Next question button can register a callback that changes the game state: st.button("Next question", type="primary", on_click=lambda: game.proceed_to_next_question()). section 9.6.2
The alternative if st.button structure is often easier for simple apps because it makes the control flow more explicit: handle the click, change state, then manually rerun when needed. Callbacks are more restricted; a callback cannot trigger an app rerun. section 9.6.2
st.button(
"Next question",
type='primary',
on_click=lambda: game.proceed_to_next_question()
)
Browse the complete button callback used to move the trivia game to its next question. section 9.6.2


















