Streamlit time input function doesn't support each single time

Question:

enter image description here

Is there any way to show the time menu like above on streamlit? This menu should show every single hour and minute. Other hand streamlit time input provides only pre defined time arrivals like 08:00 08:15 08:30 08:45 etc. I don’t want this. How can I solve this problem?

Asked By: murat taşçı

||

Answers:

  start = "00:00"
    end = "23:59"
    times = []
    start = now = datetime.datetime.strptime(start, "%H:%M")
    end = datetime.datetime.strptime(end, "%H:%M")
    while now != end:
        times.append(str(now.strftime("%H:%M")))
        now += datetime.timedelta(minutes=1)
    times.append(end.strftime("%H:%M"))
    st.multiselect('Departure hour:',times)
Answered By: murat taşçı

Improved answer:

times = []
for hours in range(0, 23):
  for minutes in range(0, 59):
    times.append(datetime.time(hours, minutes))
st.selectbox("Time", times, key="time", format_func=lambda t: t.strftime("%H:%M"))
Answered By: Martin Thøgersen
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.