How to call a function that returns values with on click

I’d like to call a function when i click on a st.form_submit_button.

I read that it is possible to use , for example, the syntax β€œon_click=my_function()”

But the problem is that my function returns values : i would normally use it like this : value1, value2=my_function() .

So how can i write it with the parameter on_click ?
β†’ like this : on_click=values1, values2=my_function() ?

I don’t think you need a callback to do that.

import streamlit as st

def my_function():
    return "foo", "bar"

with st.form(key="form"):
    text = st.text_input("Text")
    submit = st.form_submit_button()

if submit:
    value1, value2 = my_function()
    st.write(f"Text: {text}")
    st.write(f"Value 1: {value1}")
    st.write(f"Value 2: {value2}")
1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.