-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoGroupNoteGUI.py
More file actions
111 lines (90 loc) · 3.27 KB
/
AutoGroupNoteGUI.py
File metadata and controls
111 lines (90 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import tkinter as tk
from tkinter import messagebox
from pywinauto import Desktop
from threading import Thread
from AutoGroupNote import WechatAutoGroupnote
import ctypes
# 设置 DPI 缩放以适配高分屏
try:
ctypes.windll.shcore.SetProcessDpiAwareness(2)
except Exception:
pass
# 创建主窗口
root = tk.Tk()
root.title("微信接龙自动回复")
root.geometry("700x840")
root.minsize(500, 600)
# 使用统一字体
default_font = ("Microsoft YaHei UI", 10)
button_width = 24 # 统一按钮宽度
# 存储窗口列表及选中项
window_titles = []
selected_index_var = tk.IntVar(value=-1)
def refresh_window_list():
global window_titles
windows = Desktop(backend="uia").windows()
window_titles = [w.window_text() for w in windows if w.window_text().strip()]
listbox.delete(0, tk.END)
for idx, t in enumerate(window_titles):
listbox.insert(tk.END, t)
if 0 <= selected_index_var.get() < len(window_titles):
listbox.selection_set(selected_index_var.get())
def on_listbox_select(event):
try:
index = listbox.curselection()[0]
selected_index_var.set(index)
except IndexError:
pass
def start_bot():
idx = selected_index_var.get()
if idx < 0 or idx >= len(window_titles):
messagebox.showerror("错误", "请先选择一个窗口!")
return
selected_title = window_titles[idx]
content = entry_content.get().strip()
try:
delay = float(entry_delay.get().strip())
except ValueError:
messagebox.showerror("错误", "延迟必须是数字(支持小数)!")
return
if not content:
messagebox.showerror("错误", "请输入接龙内容!")
return
def worker():
bot = WechatAutoGroupnote(
window_title=selected_title,
log_out=True,
send_delay_seconds=delay
)
bot.run(content)
t = Thread(target=worker)
t.daemon = True
t.start()
messagebox.showinfo("启动", f"已启动接龙监控:{selected_title}")
def exit_program():
root.quit()
root.destroy()
# ---------- UI 布局 ----------
tk.Label(root, text="请选择要监控的微信聊天窗口:", font=default_font).pack(pady=(10, 5))
listbox = tk.Listbox(root, width=100, height=15, font=default_font, selectmode=tk.SINGLE)
listbox.pack()
listbox.bind("<<ListboxSelect>>", on_listbox_select)
# 统一按钮布局区域
btn_frame = tk.Frame(root)
btn_frame.pack(pady=10)
tk.Button(btn_frame, text="刷新窗口列表", width=button_width, font=default_font, command=refresh_window_list).pack(pady=2)
tk.Button(btn_frame, text="启动接龙监控", width=button_width, font=default_font, command=start_bot).pack(pady=2)
tk.Button(btn_frame, text="关闭程序", width=button_width, font=default_font, command=exit_program).pack(pady=2)
# 接龙内容输入
tk.Label(root, text="接龙内容:", font=default_font).pack(pady=(10, 2))
entry_content = tk.Entry(root, width=20, font=default_font)
entry_content.insert(0, "Roy")
entry_content.pack()
# 延迟时间输入
tk.Label(root, text="发送前延迟(秒):", font=default_font).pack(pady=(10, 2))
entry_delay = tk.Entry(root, width=20, font=default_font)
entry_delay.insert(0, "0")
entry_delay.pack()
# 初次刷新窗口列表
refresh_window_list()
root.mainloop()