How to set component value to default after button click?

Hi. Is it possible to set component values to default (eg: 0 for a number input component) on a button click similar to clear_on_submit for forms. I dont want to use forms for my code.

Try this.

import streamlit as st

def reset_value():
    st.session_state.numk = 0

st.number_input('enter number', min_value=0, max_value=100, key='numk')
st.write(f'number: {st.session_state.numk}')

st.button('reset', on_click=reset_value)

number input

1 Like