Maryam Ilka commited on
Commit
3819e1c
·
verified ·
1 Parent(s): d1bd74f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -6
app.py CHANGED
@@ -600,14 +600,25 @@ def attention_check1():
600
  key="att1_radio"
601
  )
602
 
603
- # استفاده از کامپوننت HTML برای دکمه سبز
604
- st.components.v1.html(f"""
605
- <button onclick="window.parent.postMessage('continue_green_clicked', '*')"
606
- style="background-color:#28a745; color:white; border:none; border-radius:8px; padding:10px 20px; font-weight:bold; width:100%; cursor:pointer;">
 
 
 
 
 
 
 
 
 
607
  ادامه
608
  </button>
609
- """, height=45)
610
-
 
 
611
  if st.session_state.get("continue_green_clicked"):
612
  if answer:
613
  st.session_state.attention_check1 = answer
@@ -616,6 +627,15 @@ def attention_check1():
616
  else:
617
  st.warning("لطفاً یک گزینه را انتخاب کنید")
618
 
 
 
 
 
 
 
 
 
 
619
 
620
  def attention_check2():
621
  """سوال توجه دوم (بدون بررسی پاسخ صحیح)"""
 
600
  key="att1_radio"
601
  )
602
 
603
+ # 1. دکمه HTML واقعی با JavaScript
604
+ html_code = """
605
+ <script>
606
+ function handleContinue() {
607
+ // ارسال داده به Streamlit
608
+ parent.document.dispatchEvent(new CustomEvent('continueGreenClicked'));
609
+ }
610
+ </script>
611
+
612
+ <button onclick="handleContinue()"
613
+ style="background-color:#28a745; color:white; border:none;
614
+ border-radius:8px; padding:10px 20px; font-weight:bold;
615
+ width:100%; cursor:pointer; margin-top:10px;">
616
  ادامه
617
  </button>
618
+ """
619
+ html(html_code, height=50)
620
+
621
+ # 2. دریافت رویداد در Streamlit
622
  if st.session_state.get("continue_green_clicked"):
623
  if answer:
624
  st.session_state.attention_check1 = answer
 
627
  else:
628
  st.warning("لطفاً یک گزینه را انتخاب کنید")
629
 
630
+ # کد JavaScript برای دریافت رویداد (در بخش اصلی برنامه)
631
+ st.components.v1.html("""
632
+ <script>
633
+ document.addEventListener('continueGreenClicked', function() {
634
+ Streamlit.setComponentValue("continue_green_clicked");
635
+ });
636
+ </script>
637
+ """)
638
+
639
 
640
  def attention_check2():
641
  """سوال توجه دوم (بدون بررسی پاسخ صحیح)"""