From 4061eac83cd349495d3d179b35c3be854ae4001b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AD=90=E6=81=BA?= <1621362626@qq.com> Date: Thu, 21 Aug 2025 16:02:08 +0800 Subject: [PATCH] for fun --- components/constants.py | 3 ++- components/page1.py | 48 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/components/constants.py b/components/constants.py index f002870..c7a33fd 100644 --- a/components/constants.py +++ b/components/constants.py @@ -16,7 +16,8 @@ indexMap = {6: "A. ", 7: "B. ", 8: "C. ", 9: "D. "} # 全局 bottom_options = ["未做过的题", "错过的题", ] instructions = f"""第二行啥也不选就是不过滤,全部的题 -题目是加权平均抽取,默认权重为3,对一次减1,错一次加2.""" +题目是加权平均抽取,默认权重为3,对一次减1,错一次加2. +源代码https://v.zikai.wang/zikai/cyzg""" # 样式 # 创建字体 diff --git a/components/page1.py b/components/page1.py index 5f21007..a82fd47 100644 --- a/components/page1.py +++ b/components/page1.py @@ -1,4 +1,7 @@ import tkinter as tk +import os +import platform +import webbrowser from tkinter import ttk from components import * @@ -56,9 +59,50 @@ class Page1: text_widget.insert(tk.END, instructions) text_widget.config(state=tk.DISABLED) - def setup_styles(self): - """设置 ttk 样式""" + # just for fun + url = "https://v.zikai.wang/zikai/cyzg" + start_pos = instructions.find(url) + if start_pos != -1: + # 计算起始和结束索引(tkinter 使用 "行.列" 格式) + start_index = f"1.0 + {start_pos} chars" + end_index = f"{start_index} + {len(url)} chars" + # 创建一个超链接标签 + text_widget.tag_add("link", start_index, end_index) + text_widget.tag_config("link", + foreground="blue", + underline=True, + font=(FONT_FAMILY, 12, "underline")) + + # 定义点击事件 + def open_link(event): + try: + webbrowser.open(url) + except Exception as e: + print(e) + + try: + os_name = platform.system() + + if os_name == "Windows": + os.system(f'echo {url} | clip') + elif os_name == "Darwin": + os.system(f'echo "{url}" | pbcopy') + else: + os.system(f'echo "{url}" | xclip -selection clipboard') + except Exception as e: + print(e) + + def on_enter(event): + text_widget.config(cursor="hand2") + + def on_leave(event): + text_widget.config(cursor="") + + # 绑定事件 + text_widget.tag_bind("link", "", open_link) # 左键点击 + text_widget.tag_bind("link", "", on_enter) # 鼠标进入 + text_widget.tag_bind("link", "", on_leave) # 鼠标离开 def top_selected(self): """返回第一行中被选中的项"""