Spaces:
Sleeping
Sleeping
Maryam Ilka commited on
Create custom_button.py
Browse files- custom_button.py +26 -0
custom_button.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit.components.v1 as components
|
| 2 |
+
|
| 3 |
+
# کامپوننت اختصاصی
|
| 4 |
+
def custom_button(text, key=None):
|
| 5 |
+
components.html(
|
| 6 |
+
f"""
|
| 7 |
+
<!DOCTYPE html>
|
| 8 |
+
<html>
|
| 9 |
+
<body>
|
| 10 |
+
<button id="{key}"
|
| 11 |
+
style="background-color:#28a745;color:white;border:none;
|
| 12 |
+
border-radius:8px;padding:10px 20px;font-weight:bold;
|
| 13 |
+
width:100%;cursor:pointer;"
|
| 14 |
+
onclick="sendClick()">
|
| 15 |
+
{text}
|
| 16 |
+
</button>
|
| 17 |
+
<script>
|
| 18 |
+
function sendClick() {{
|
| 19 |
+
window.parent.postMessage("{key}_clicked", "*");
|
| 20 |
+
}}
|
| 21 |
+
</script>
|
| 22 |
+
</body>
|
| 23 |
+
</html>
|
| 24 |
+
""",
|
| 25 |
+
height=50
|
| 26 |
+
)
|