Using st.text_input()

Running it locally. python version - 3.10.9 and streamlit version - 1.31.1

Creating user field where the value is auto generated and non-editable. But when I make that change, the label is also getting disabled. In the below image, “crop variety” label doesn’t look similar to " plot name" label,

The respective code,

crop_variety = st.text_input("Crop Variety", "TME 419", key="crop_variety",disabled=True,label_visibility="visible")
plot_name = st.selectbox("Plot Name/Code", plot_name_options, key="plot_name")

Hi @Joemol_94

It does seem that disabling the widget applies to both the widget and its label.

Alternatively what you could try is making the labels hidden as in label_visibility=“hidden” for both widgets, then manually create the label using a text widget such as st.write, st.markdown or st.caption (if you’d like the labels to be smaller).

Hope this helps!

Hi @dataprofessor,

Thanks for the quick response. I made the suggested change, but that creates a space between the label and value fields. How to reduce this spacing?

st.markdown("Crop Variety")
crop_variety = st.text_input("", "TME 419", key="crop_variety",disabled=True,label_visibility="hidden")

Use label_visibility="collapsed".

1 Like

Yes that worked. Thank you!

1 Like

Thanks @Goyo for catching label_visibility=collapsed

Finally, the code snippet would be:

import streamlit as st

st.markdown("Crop Variety")
crop_variety = st.text_input("", "TME 419", key="crop_variety",disabled=True,label_visibility="collapsed")

plot_name_options = ['K1', 'K2', 'K3']
st.markdown("Plot Name/Code")
crop_variety = st.selectbox("", plot_name_options, key="plot_name",disabled=True,label_visibility="collapsed")

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.