How to make transparent by st.color_picker

I am trying to use st.color_picker to make different colors for drawing.

The case:
I am drawing a paste by PIL, I want to have a transparent bg option for the paste image.
I can not achieve that by st.color_picker. and havn’t found the answer in the forum.

Does any one know how to do, thank you very much
or is it possible to use RGBA mode in st.color_picker?

Hi @calvinish

You could use something like this:

vcolor = st.color_picker('Pick A Color', '#00f900')
st.write('The current color is', vcolor)

st.markdown(f"<span style='background-color:{vcolor}'>This is the chosen colour</span>", True)
st.markdown(f"<span style='background-color:{vcolor}; opacity:0.2; '>and this is transparent</span>", True)

Just change the opacity in the above code to 0 - I have kept it to 0.2 so that you can see that it can be made transparent.

Hope this helps. :slight_smile:

Cheers

@Shawn_Pereira Thanks for your advice, I also find similar solution on the forum. But I am just curious about whether st.color_picker can have the function of different color mood. Like in powerpoint and keynote, they have more color choice.
image image

I know CSS and HTML can also show different color, however I am not familiar with that,
thanks for your help :grinning:

1 Like

I think RGBA support in the color picker is worth a feature request.

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