When I click a button on the sidebar, the color changes from black to red. How do I reset the colors? My expectation is the color would change on hover and restore on button up. Instead it remains red.
import streamlit as st
if st.sidebar.button("Do it"): # turns from black to red then stays red.
st.write('Did it')
When I run that exact code as you’ve put it, it behaves like this for me: it changes to light red on hover, goes darker red on click, and then changes back to light red. If you click anywhere else on the page, it then turns to black. It doesn’t stay red.
I actually didn’t notice that it turns back to black if I click elsewhere. My expectation is that the button will restore black on button up either automatically or at least a programmatic way to do so.
Perhaps this is actually a focus issue specific to streamlit. The button has focus after a click. The solution is to change focus to an input box in the main area, I don’t believe streamlit has a built-in way to change focus without resorting to css. So I might need to hack the button if I want my desired behavior.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.