How to show a progressbar based on the execution of a fucntion

Hi,

  with st.container(key="btn-container-test"):
                        continueBtn =st.form_submit_button("login", type="primary")
                        if continueBtn:
                                        custom_function1()
                                        some code
                                        custom_function2()
                                         

what I’m looking for is to set a progressbar when i click continueBtn btn, and the progressbar should end at the same time of the code inside the continueBtn btn.

could you help please ?

Just create the bar at the beginning, then add calls to bar.progress() in the places where you know the progress.

continueBtn = st.button("login", type="primary")
if continueBtn:
    bar = st.progress(0.0, text="Progress")
    custom_function1()
    bar.progress(1 / 3)
    some code
    bar.progress(2 / 3)
    custom_function2()
    bar.progress(1.0)
1 Like

thanks for your time , is there a way please to display the percentage ?

Use the text argument to display whatever text you want.

continueBtn = st.button("login", type="primary")
if continueBtn:
    bar = st.progress(0.0, text=f"{0.0}%")
    custom_function1()
    bar.progress(1 / 3, text=f"{100 / 3}%")
    some code
    bar.progress(2 / 3, text=f"{200 / 3}%")
    custom_function2()
    bar.progress(1.0, text=f"{100.0}%")

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