The program offers the number format as Default in a,b format but I want to show as a:b format
How can I change this? I tried below but it didn’t work:
st.number_input(“time”)).replace(" , " , " : ")
The program offers the number format as Default in a,b format but I want to show as a:b format
How can I change this? I tried below but it didn’t work:
st.number_input(“time”)).replace(" , " , " : ")
Hi @murat_tasci -
It doesn’t work, because the value returned by number_input
is an int
or float
. However, the function does have a parameter format
that allows you to change the display within Streamlit. See the docs for more information:
Best,
Randy
Hi @murat_tasci , wouldn’t it be better to use the time widget for time, instead of the number input? That way, you would get your ‘:’ character too.
The reference is : st.time_input - Streamlit Docs
Cheers
Hi @Shawn_Pereira
I want to use time widget but as far as I know it is not possible to see every single time value on time widget menu like 00:01, 00:02, 00:03…00:04 … 12:00 etc. If it is possible, could you share the code for this?
Note:The values has intervals as 15 mins last have I seen streamlit widget menu. (00:15, 00:30, 00:45, 1:00 etc.)
Hi @murat_tasci , in one of my projects, I implemented a selectbox for time which had a tuple containing sorted elements 5 minutes apart. (i.e. 00:00, 00:05, 00:10…00:15…). You could try any method that suits your purpose.
Cheers
Hi @randyzwitch, I have a question which is over the picture too.
Multi-select solution:
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)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.