Key Press down event in Streamlit SelectBox or Text

Good day,

May I know can Key Press down event be captured in Streamlit selectbox or text?

The scenario here is like:
selectbox is working fine for a static list and return suggested options according to what I input character by character.

However, a static list is not applicable in my case. I need a dynamic list, whenever I input a character the list shall contain the values returned from a REST API call using the already input characters.

For example: I’ll input g-o-o-d, the API will be called 4 times using “g”,"go“,“goo”,“good” and update the options list for selectbox accordingly in sequence. Is there any feature that can support my scenario?

Thanks for any suggestion from community in advance.

Hey @zhll2046,

It sounds like you could accomplish this by using an on_change function for your st.text_input widget. The function would be called when the text input’s value changes. Check out the doc here

Actually I need a selectbox, text_input doesn’t have the dropdown list to choose.

Unfortunately, Streamlit doesn’t natively support key press events, but you could add on_change event to your selectbox (related doc here)