File size: 941 Bytes
6ce3856
c503554
7fbaf23
cedaed3
 
 
 
 
 
 
 
 
 
 
 
7fbaf23
cedaed3
 
 
 
 
7fbaf23
cedaed3
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
import streamlit.components.v1 as components

# JavaScript code for confetti animation
confetti_animation_script = """
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.2/dist/confetti.browser.min.js"></script>
<script>
    function triggerConfetti() {
        confetti({
            angle: randomInRange(55, 125),
            particleCount: randomInRange(50, 100),
            origin: { y: 0.6 },
            spread: randomInRange(50, 70),
        });
    }

    function randomInRange(min, max) {
        return Math.random() * (max - min) + min;
    }
</script>
"""

# Display the confetti animation script
components.html(confetti_animation_script, height=0)

# Button to trigger confetti using onclick method
confetti_button = st.button("Click for Confetti", on_click="triggerConfetti()")

if confetti_button:
    st.empty()  # Optional, clears the button after clicking
    st.write("Confetti time!")