How to add a function to a button?

Hey @Junkrat, welcome to Streamlit!

The st.button function returns True if the button was clicked by the user during the most recent run of your app. So to attach your function to the button, you could do this:

if st.button('add'):
    result = add(1, 2)
    st.write('result: %s' % result)
5 Likes