How to make a timer?

Hi!

You could use the metrics and display a countdown:

import streamlit as st
import time

st.set_page_config()

ph = st.empty()
N = 5*60
for secs in range(N,0,-1):
    mm, ss = secs//60, secs%60
    ph.metric("Countdown", f"{mm:02d}:{ss:02d}")
    time.sleep(1)

countdown

But there is a huge catch: the app wont be able to do anything else until the countdown ends (It stays on the countdown loop). Iโ€™d love to know if thereโ€™s a way to avoid this!

4 Likes