input上添加disabled=“true“,点击事件失效处理办法

当我们给input标签上添加disabled="true"时,再添加点击事件,点击事件会不生效,处理办法如下:

给input标签添加样式style="pointer-events: none;"

代码如下:

<input style="pointer-events: none;" v-model="address" disabled="true" type="text" value=""  />

import PySimpleGUI as Py import time import os # ======== 全局设置 ======== Py.theme(&#39;Default&#39;) a = &#39; 漫息!&#39; b = &#39;【&#39; # 图片路径定义(请确保这些路径在你电脑上真实存在) image_path2 = "D:/software/demo/pythonProject/images/image2.png" image_path3 = "D:/software/demo/pythonProject/images/image3.png" image_path4 = "D:/software/demo/pythonProject/images/image4.png" image_path5 = "D:/software/demo/pythonProject/images/image5.png" image_path6 = "D:/software/demo/pythonProject/images/image6.png" image_path7 = "D:/software/demo/pythonProject/images/image7.png" image_path8 = "D:/software/demo/pythonProject/images/image8.png" image_path9 = "D:/software/demo/pythonProject/images/image9.png" # 检查图片是否存在 def check_image(path): if not os.path.exists(path): print(f"[!] 图片不存在: {path}") return None return path image_path2 = check_image(image_path2) image_path3 = check_image(image_path3) image_path4 = check_image(image_path4) image_path5 = check_image(image_path5) image_path6 = check_image(image_path6) image_path7 = check_image(image_path7) image_path8 = check_image(image_path8) image_path9 = check_image(image_path9) # ======== 全局窗口变量 ======== window10 = None # 用于保存 window10 的引用 # ======== 关闭 window10 的安全函数 ======== def close_window10(): global window10 if window10: try: window10.close() except Exception: pass window10 = None # ======== 周期性提醒功能 ======== reminder_running = False def run_periodic_reminder(): global reminder_running if reminder_running: print("[!] 提醒功能已在运行,忽略重复调用") return reminder_running = True layout9 = [ [Py.Image(key=&#39;img9&#39;, filename=image_path9) if image_path9 else Py.Text("加载失败")], [Py.Text("天", font=("华文楷体", 10), text_color=&#39;blue&#39;)], [Py.Text("📌 周期性提醒已激活:每次取消后10秒自动重试")], [Py.Multiline("", size=(60, 4), key=&#39;-OUTPUT-&#39;, disabled=True, autoscroll=True)], [Py.Button(&#39;退出&#39;, key=&#39;EXIT&#39;, button_color=(&#39;#800000&#39;, &#39;Silver&#39;)), Py.Text("", font=("华文楷体", 10), text_color=&#39;red&#39;)] ] window9_position = (1795, 300) window9 = Py.Window(&#39;&#39;, layout9, size=(460, 490), finalize=True, location=window9_position) window9.keep_on_top_set() next_popup_time = time.time() + 1 reminder_active = True popup_active = False input_popup = None can_exit = False # 控制是否允许退出 def show_input_popup(): layout_popup = [ [Py.Text(&#39;:&#39;)], [Py.Input(key=&#39;-INPUT-&#39;, size=(6, 1), font=("Arial", 20), focus=True), Py.Text(&#39;或&#39;, font=("华文楷体", 16), text_color=&#39;#000000&#39;), Py.Text(&#39;动&#39;, font=("华文楷体", 22), text_color=&#39;red&#39;, background_color=&#39;#86A8FF&#39;)], [Py.Button(&#39;属于&#39;, key=&#39;BELONG&#39;, button_color=(&#39;#800000&#39;, &#39;white&#39;), bind_return_key=True), Py.Push(), Py.Button(&#39;不属于&#39;, key=&#39;NOT_BELONG&#39;, button_color=(&#39;#000000&#39;, &#39;white&#39;))] ] windowpopup_position = (1890, 680) return Py.Window(&#39;&#39;, layout_popup, keep_on_top=True, modal=True, location=windowpopup_position, finalize=True) try: while True: # 主窗口读取事件 try: event9, values9 = window9.read(timeout=100) except Exception as e: if "wrapped C/C++ object has been deleted" in str(e) or "TclError" in str(e): print("[INFO] 窗口已被系统关闭,退出提醒循环。") break else: print(f"[ERROR] Unexpected error: {e}") break # 处理退出按钮:只有 can_exit 为 True 时才响应 if event9 == &#39;EXIT&#39;: if not can_exit: window9[&#39;-OUTPUT-&#39;].update("⚠️ 尚未完成验证,无法退出\n", append=True) continue else: close_window10() layout10 = [ [Py.Image(key=&#39;img2&#39;, filename=image_path2) if image_path2 else Py.Text("加载失败")], [Py.Text(a, size=(23, 200), auto_size_text=True)] ] window10_pos = (2340, 145) global window10 window10 = Py.Window(&#39;&#39;, layout10, size=(220, 750), location=window10_pos, finalize=True) window10.keep_on_top_set() break if event9 in (None, Py.WINDOW_CLOSED): break now = time.time() # 触发新弹窗 if reminder_active and not popup_active and next_popup_time and now >= next_popup_time: popup_active = True try: input_popup = show_input_popup() except Exception as e: print(f"[Error] 无法创建弹窗: {e}") popup_active = False next_popup_time = now + 10 continue # 处理 input_popup 弹窗逻辑 if input_popup: try: event_p, values_p = input_popup.read(timeout=100) except Exception as e: print(f"[Popup Error] {e}") input_popup = None popup_active = False window9[&#39;-OUTPUT-&#39;].update("⚠️ 弹窗异常关闭,60秒后重试...\n", append=True) next_popup_time = time.time() + 60 continue if event_p == Py.WINDOW_CLOSED or event_p is None: try: input_popup.close() except Exception: pass input_popup = None popup_active = False window9[&#39;-OUTPUT-&#39;].update("⛔ 弹窗被用户关闭,60秒后将再次提醒...\n", append=True) next_popup_time = time.time() + 60 continue user_input = values_p.get(&#39;-INPUT-&#39;, &#39;&#39;).strip() valid_number = False try: if user_input: float(user_input) valid_number = True except ValueError: pass # 安全更新按钮状态 try: input_popup[&#39;BELONG&#39;].update(disabled=not valid_number) except Exception: pass # 忽略失效窗口更新 if event_p == &#39;BELONG&#39; and valid_number: try: num = float(user_input) formatted_num = int(num) if num.is_integer() else num window9[&#39;-OUTPUT-&#39;].update(f"✔️ 录入成功:{formatted_num} —— 提醒停止\n", append=True) reminder_active = False next_popup_time = None can_exit = True except Exception: window9[&#39;-OUTPUT-&#39;].update(f"❌ 输入处理失败:&#39;{user_input}&#39;\n", append=True) next_popup_time = time.time() + 60 finally: try: input_popup.close() except Exception: pass input_popup = None popup_active = False elif event_p == &#39;NOT_BELONG&#39;: try: input_popup.close() except Exception: pass input_popup = None popup_active = False window9[&#39;-OUTPUT-&#39;].update("⛔ 用户取消,60秒后将再次提醒...\n", append=True) next_popup_time = time.time() + 60 finally: if window9: try: window9.close() except Exception as e: print(f"[Cleanup] Failed to close window9: {e}") reminder_running = False # ✅ 可以直接赋值,无需再次 global # ======== 单次流程函数 run_single_flow ======== def run_single_flow(): input_history = [] current_text = &#39;&#39; layout4 = [ [Py.Image(key=&#39;img4&#39;, filename=image_path4) if image_path4 else Py.Text("加载失败")], [Py.Text("请在5秒内输入当前动量,之后5秒无操作将自动记录:")], [Py.Input(key=&#39;-INPUT-&#39;, size=(10, 1), font=("Arial", 20), focus=True), Py.Text("", size=(60, 1), key=&#39;-STATUS-&#39;)], [Py.Text(":")], [Py.Frame(&#39;&#39;, [[Py.Text("", size=(48, 15), key=&#39;-HISTORY-&#39;, relief=&#39;sunken&#39;, background_color=&#39;white&#39;, text_color=&#39;black&#39;, font=(&#39;Courier&#39;, 15))]], size=(590, 75), pad=10)], [Py.Button(&#39;美边&#39;, key=&#39;MEIBIAN&#39;, button_color=(&#39;#006400&#39;, &#39;Silver&#39;), disabled=True)], [Py.Button(&#39;同向&#39;, key=&#39;TONGXIANG&#39;, button_color=(&#39;#000000&#39;, &#39;white&#39;), disabled=True), Py.Button(&#39;不符合&#39;, key=&#39;CANCEL&#39;, button_color=(&#39;#800000&#39;, &#39;Silver&#39;))] ] window4_position = (1795, 300) window4 = Py.Window(&#39;&#39;, layout4, size=(460, 500), resizable=True, location=window4_position, finalize=True) window4.keep_on_top_set() last_input_time = None while True: event4, values4 = window4.read(timeout=100) if event4 == Py.WINDOW_CLOSED or event4 == &#39;CANCEL&#39;: window4.close() return raw_input = values4[&#39;-INPUT-&#39;].strip() changed = raw_input != current_text current_text = raw_input # 验证是否为有效数字 valid_number = False try: if current_text: float(current_text) valid_number = True except ValueError: pass # 更新按钮状态 window4[&#39;MEIBIAN&#39;].update(disabled=not valid_number) window4[&#39;TONGXIANG&#39;].update(disabled=not valid_number) if valid_number: window4[&#39;-STATUS-&#39;].update(f"✅ 输入中 &#39;{current_text}&#39; ... 可提交") elif current_text: window4[&#39;-STATUS-&#39;].update("❌ 请输入有效的数字") else: window4[&#39;-STATUS-&#39;].update("") # 自动提交逻辑 if valid_number and changed: last_input_time = time.time() elif valid_number and last_input_time is not None: elapsed = time.time() - last_input_time remaining = max(0, int(5 - elapsed + 0.9)) if remaining > 0: window4[&#39;-STATUS-&#39;].update(f"⏳ 还剩 {remaining} 秒自动提交...") else: try: num = float(current_text) formatted_num = int(num) if num.is_integer() else num input_history.append(formatted_num) history_str = &#39; &#39;.join(map(str, input_history)) window4[&#39;-HISTORY-&#39;].update(history_str) window4[&#39;-STATUS-&#39;].update("🎉 已自动记录!") window4[&#39;-INPUT-&#39;].update(&#39;&#39;) current_text = &#39;&#39; last_input_time = None except Exception: window4[&#39;-STATUS-&#39;].update("❌ 提交失败") finally: window4[&#39;MEIBIAN&#39;].update(disabled=True) window4[&#39;TONGXIANG&#39;].update(disabled=True) # 处理按钮事件 if event4 == &#39;MEIBIAN&#39; and valid_number: close_window10() window2.close() window4.close() run_periodic_reminder() return elif event4 == &#39;TONGXIANG&#39; and valid_number: window4.close() _run_tongxiang_flow(input_history) return def _run_tongxiang_flow(input_history): current_text = &#39;&#39; layout5 = [ [Py.Image(key=&#39;img5&#39;, filename=image_path5) if image_path5 else Py.Text("加载失败")], [Py.Text("请在5秒内输入当前动量,之后5秒无操作将自动记录:")], [Py.Input(key=&#39;-INPUT-&#39;, size=(10, 1), font=("Arial", 20)), Py.Text("", size=(60, 1), key=&#39;-STATUS-&#39;)], [Py.Frame(&#39;&#39;, [[Py.Text("", size=(49, 15), key=&#39;-HISTORY-&#39;, relief=&#39;sunken&#39;, background_color=&#39;white&#39;, text_color=&#39;black&#39;, font=(&#39;Courier&#39;, 15))]], size=(410, 50), pad=10)], [Py.Button(&#39;进入弱&#39;, key=&#39;RUO&#39;, button_color=(&#39;#000000&#39;, &#39;Silver&#39;), disabled=True), Py.Button(&#39;进入强&#39;, key=&#39;QIANG&#39;, button_color=(&#39;#000000&#39;, &#39;Silver&#39;), disabled=True)] ] window5_position = (1795, 300) window5 = Py.Window(&#39;&#39;, layout5, size=(460, 430), resizable=True, location=window5_position, finalize=True) window5.keep_on_top_set() last_input_time = None while True: event5, values5 = window5.read(timeout=100) if event5 == Py.WINDOW_CLOSED: window5.close() return raw_input = values5[&#39;-INPUT-&#39;].strip() changed = raw_input != current_text current_text = raw_input valid_number = False try: if current_text: float(current_text) valid_number = True except ValueError: pass window5[&#39;RUO&#39;].update(disabled=not valid_number) window5[&#39;QIANG&#39;].update(disabled=not valid_number) if valid_number: window5[&#39;-STATUS-&#39;].update(f"✅ 输入中 &#39;{current_text}&#39; ... 可提交") elif current_text: window5[&#39;-STATUS-&#39;].update("❌ 请输入有效的数字") else: window5[&#39;-STATUS-&#39;].update("") if valid_number and changed: last_input_time = time.time() if valid_number and last_input_time is not None: elapsed = time.time() - last_input_time if elapsed >= 5.0: try: num = float(current_text) formatted_num = int(num) if num.is_integer() else num input_history.append(formatted_num) history_str = &#39; &#39;.join(map(str, input_history)) window5[&#39;-HISTORY-&#39;].update(history_str) window5[&#39;-STATUS-&#39;].update("🎉 已自动记录!") window5[&#39;-INPUT-&#39;].update(&#39;&#39;) current_text = &#39;&#39; last_input_time = None except Exception: window5[&#39;-STATUS-&#39;].update("❌ 提交失败") finally: window5[&#39;RUO&#39;].update(disabled=True) window5[&#39;QIANG&#39;].update(disabled=True) if event5 == &#39;RUO&#39; and valid_number: window5.close() _run_zhongjin_flow(&#39;RUO&#39;) return elif event5 == &#39;QIANG&#39; and valid_number: window5.close() _run_zhongjin_flow(&#39;QIANG&#39;) return def _run_zhongjin_flow(mode): recorded_numbers = [] title = "【中进】" if mode == &#39;RUO&#39; else "出现【再" btn_key = &#39;ZHONGJIN&#39; if mode == &#39;RUO&#39; else &#39;CHUXIAN_ZAI&#39; layout = [ [Py.Image(key=&#39;img6&#39; if mode == &#39;RUO&#39; else &#39;img7&#39;, filename=image_path6 if mode == &#39;RUO&#39; else image_path7)], [Py.Input(key=&#39;-INPUT-&#39;, size=(10, 1), font=("Arial", 20), do_not_clear=False)], [Py.Button(title, key=btn_key, button_color=(&#39;#006400&#39;, &#39;Silver&#39;), bind_return_key=True, disabled=True), Py.Button(&#39;不于进&#39;, key=&#39;CLEAR_INPUT&#39;, button_color=(&#39;#800000&#39;, &#39;Silver&#39;))], [Py.HorizontalSeparator()], [Py.Text("", size=(50, 2), key=&#39;-HISTORY-&#39;, relief=&#39;sunken&#39;, background_color=&#39;white&#39;, text_color=&#39;black&#39;)] ] pos_y = 300 if mode == &#39;RUO&#39; else 350 window = Py.Window(&#39;&#39;, layout, size=(460, 395), location=(1795, pos_y), finalize=True) window.keep_on_top_set() while True: event, values = window.read() if event in (None, Py.WINDOW_CLOSED): break user_input = values[&#39;-INPUT-&#39;].strip() valid_number = False try: if user_input: float(user_input) valid_number = True except ValueError: pass window[btn_key].update(disabled=not valid_number) if event == btn_key and valid_number: close_window10() window2.close() try: num = float(user_input) formatted_num = int(num) if num.is_integer() else num recorded_numbers.append(formatted_num) history_text = &#39; &#39;.join(map(str, recorded_numbers)) window[&#39;-HISTORY-&#39;].update(history_text) window[&#39;-INPUT-&#39;].update(&#39;&#39;) except Exception: pass window.close() run_periodic_reminder() break elif event == &#39;CLEAR_INPUT&#39;: window[&#39;-INPUT-&#39;].update(&#39;&#39;) window.close() # ======== 新增:_run_juezhan_flow ======== def _run_juezhan_flow(): current_text = &#39;&#39; layout8 = [ [Py.Image(key=&#39;img8&#39;, filename=image_path8) if image_path8 else Py.Text("加载失败")], [Py.Text("决战", font=("华文楷体", 13), text_color=&#39;blue&#39;)], [Py.Input(key=&#39;-INPUT-&#39;, size=(10, 1), font=("Arial", 20), focus=True), Py.Text("", size=(60, 1), key=&#39;-STATUS-&#39;)], [Py.Frame(&#39;&#39;, [[Py.Text("", size=(48, 15), key=&#39;-HISTORY-&#39;, relief=&#39;sunken&#39;, background_color=&#39;white&#39;, text_color=&#39;black&#39;, font=(&#39;Courier&#39;, 15))]], size=(590, 75), pad=10)], [Py.Button(&#39;败退&#39;, key=&#39;BUTUI&#39;, button_color=(&#39;#006400&#39;, &#39;Silver&#39;), disabled=True), Py.Button(&#39;反击&#39;, key=&#39;FANJI&#39;, button_color=(&#39;#006400&#39;, &#39;Silver&#39;), disabled=True), Py.Button(&#39;不符合&#39;, key=&#39;CANCEL&#39;, button_color=(&#39;#800000&#39;, &#39;Silver&#39;))] ] window8_position = (1795, 300) window8 = Py.Window(&#39;&#39;, layout8, size=(460, 470), resizable=True, location=window8_position, finalize=True) window8.keep_on_top_set() input_history = [] last_input_time = None while True: event8, values8 = window8.read(timeout=100) if event8 == Py.WINDOW_CLOSED or event8 == &#39;CANCEL&#39;: window8.close() return raw_input = values8[&#39;-INPUT-&#39;].strip() changed = raw_input != current_text current_text = raw_input valid_number = False try: if current_text: float(current_text) valid_number = True except ValueError: pass window8[&#39;BUTUI&#39;].update(disabled=not valid_number) window8[&#39;FANJI&#39;].update(disabled=not valid_number) if valid_number: window8[&#39;-STATUS-&#39;].update(f"✅ 输入中 &#39;{current_text}&#39; ... 可提交") elif current_text: window8[&#39;-STATUS-&#39;].update("❌ 请输入有效的数字") else: window8[&#39;-STATUS-&#39;].update("") if valid_number and changed: last_input_time = time.time() if valid_number and last_input_time is not None: elapsed = time.time() - last_input_time if elapsed >= 5.0: try: num = float(current_text) formatted_num = int(num) if num.is_integer() else num input_history.append(formatted_num) history_str = &#39; &#39;.join(map(str, input_history)) window8[&#39;-HISTORY-&#39;].update(history_str) window8[&#39;-STATUS-&#39;].update("🎉 已自动记录!") window8[&#39;-INPUT-&#39;].update(&#39;&#39;) current_text = &#39;&#39; last_input_time = None except Exception: window8[&#39;-STATUS-&#39;].update("❌ 提交失败") finally: window8[&#39;BUTUI&#39;].update(disabled=True) window8[&#39;FANJI&#39;].update(disabled=True) if event8 in (&#39;BUTUI&#39;, &#39;FANJI&#39;) and valid_number: close_window10() window2.close() window8.close() run_periodic_reminder() return # ======== 主窗口 layout1 & window1 ======== layout1 = [[Py.Button(b, button_color=(&#39;#006400&#39;, &#39;white&#39;), font=("华文楷体", 12))]] window1_position = (514, 24) window1 = Py.Window(&#39;&#39;, layout1, size=(1532, 44), no_titlebar=True, location=window1_position, finalize=True) window1.keep_on_top_set() # ======== 辅助窗口 layout2 & window2 ======== layout2 = [ [Py.Image(key=&#39;img2&#39;, filename=image_path2) if image_path2 else Py.Text("加载失败")], [Py.Text(a, size=(23, 200), auto_size_text=True)] ] window2_position = (2340, 145) window2 = Py.Window(&#39;&#39;, layout2, size=(220, 750), no_titlebar=True, location=window2_position, finalize=True) window2.keep_on_top_set() # ======== 主事件循环 ======== while True: event1, values1 = window1.read() if event1 == Py.WIN_CLOSED: break if event1 == b: layout3 = [ [Py.Image(key=&#39;img3&#39;, filename=image_path3) if image_path3 else Py.Text("加载失败")], [Py.Button(&#39;第1&#39;, key=&#39;TYPE1&#39;, button_color=(&#39;#006400&#39;, &#39;white&#39;)), Py.Push(), Py.Button(&#39;第3&#39;, key=&#39;TYPE3&#39;, button_color=(&#39;#006400&#39;, &#39;white&#39;))] ] window3_position = (1795, 400) window3 = Py.Window(&#39;交易类型&#39;, layout3, size=(460, 190), location=window3_position, finalize=True, keep_on_top=True) window3.keep_on_top_set() while True: event3, values3 = window3.read() if event3 == Py.WINDOW_CLOSED: break if event3 == &#39;TYPE1&#39;: window3.close() run_single_flow() break if event3 == &#39;TYPE3&#39;: window3.close() _run_juezhan_flow() break try: window3.close() except Exception: pass # ======== 清理资源 ======== try: window1.close() window2.close() close_window10() except Exception: pass 在窗口点击【中进】或者出现【再,运行失败run_periodic_reminder()
最新发布
11-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值