St.button bug

If you’re creating a debugging post, please include the following info:

  1. Are you running your app locally or is it deployed? locally
  2. If your app is deployed:
    a. Is it deployed on Community Cloud or another hosting platform? no
    b. Share the link to the public deployed app. n/A
  3. Share the link to your app’s public GitHub repository (including a requirements file).
  4. Share the full text of the error message (not a screenshot). no error
  5. Share the Streamlit and Python versions. current

The following code runs the “on-click” on screen load. Unless I’m missing something the on-click should only run when I click the button.

import streamlit as st

def test():
st.button(‘Press me!’, key=“s-but1”, on_click=test())

FYI… my indent on the st.write(“test”) line was removed when I submitted the code, please adjust accordingly if you try this test. Python version: 3.12.3

Remove the () in test on the on_click.

def test():

st.button('Press me!', key='s-but1', on_click=test)

To format the code, select it and press the format button.


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