How to add emoji to a button

st.button("Click ME - " + str(i+1))

How do I add a emoji in my button?

Hi @Hiba_Fatima :wave:

You should be able to copy+paste your favorite emojis to the label argument for st.button like so:

import streamlit

st.button("Click Me ๐Ÿ‘ˆ")

image

Iโ€™ve used sites like Get Emoji and Emoji Finder search for emojis.

Hereโ€™s a fun, reproducible example where the emoji used in st.button updates with every click. It makes use of Streamlitโ€™s Session State API and callbacks:

import streamlit as st
import random

# callback to update emojis in Session State
# in response to the on_click event
def random_emoji():
    st.session_state.emoji = random.choice(emojis)

# initialize emoji as a Session State variable
if "emoji" not in st.session_state:
    st.session_state.emoji = "๐Ÿ‘ˆ"

emojis = ["๐Ÿถ", "๐Ÿฑ", "๐Ÿญ", "๐Ÿน", "๐Ÿฐ", "๐ŸฆŠ", "๐Ÿป", "๐Ÿผ"]

st.button(f"Click Me {st.session_state.emoji}", on_click=random_emoji)

button-emoji

Happy Streamlitโ€™ing! :balloon:
Snehan

6 Likes