解決したいこと
セレクトボックスとリストを対応させ、
(R, G, B = colorList[0], colorList[1], colorList[2]
)
カラーピッカーで色を割り当てたいです。
(colorList = ["#ff0000", "#00ff00", "#0000ff"]
)
以下が試したコードです。
python
1import streamlit as st 2 3# https://github.com/streamlit/streamlit/issues/1076 4options = "RGB" 5index = st.selectbox( 6 "selectbox", 7 range(len(options)), 8 format_func=lambda x: options[x] 9 ) 10 11if "colorList" not in st.session_state: 12 st.session_state.colorList = ["#000000" for _ in range(3)] 13 14color = st.color_picker( 15 "color_picker", 16 st.session_state.colorList[index] 17 ) 18 19st.session_state.colorList[index] = color
コメントアウトしたサイトを参考にインデックスを取得
↓
st.session_state
でリスト colorList
を作成
↓
カラーピッカーで選択した色をリストに割り当て
というような感じなのですが、うまくいきません。
原因、直す部分を教えてください。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー