for fun
This commit is contained in:
@@ -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", "<Button-1>", open_link) # 左键点击
|
||||
text_widget.tag_bind("link", "<Enter>", on_enter) # 鼠标进入
|
||||
text_widget.tag_bind("link", "<Leave>", on_leave) # 鼠标离开
|
||||
|
||||
def top_selected(self):
|
||||
"""返回第一行中被选中的项"""
|
||||
|
||||
Reference in New Issue
Block a user