So I want to create 2 buttons in a column, the first one for choosing attachments and the second one for folders, but theirs a huge gap between the two, how can I make it evenly closer to each other?
col1, col2 = st.columns([1,1]) # Adjust column ratios as needed
with col1:
if st.button("Button 1"):
st.write("Button 1 clicked")
with col2:
if st.button("Button 2"):
st.write("Button 2 clicked")
You can either create a third empty column like @Shawn_Pereira suggested, which is my usual method. Or you can use the “use_container_width = True” attribute on the button to make them fill the screen .
col1, col2 = st.columns([1,1]) # Adjust column ratios as needed
with col1:
if st.button("Button 1", use_container_width=True):
st.write("Button 1 clicked")
with col2:
if st.button("Button 2", use_container_width=True):
st.write("Button 2 clicked")
You will need to play with your st.columns array. For example:
#This will produce 4 columns, with the 3rd column being 10 times larger than the rest.
columns = st.columns((1,1,10,1))
with columns[0]:
st.button("Button 1", use_container_width=True)
with columns[1]:
st.button("Button 2", use_container_width=True)
# No usage of 3rd position on the columns.
with columns[3]:
st.button("Button 3", use_container_width=True) #<- Button on the right
Cheers
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.