1. ai生成1000字情书(或者其他好玩的)
2. 放到消息里会自动识别自动断句
3. 效果
源码
import pyautogui
import pyperclip
import time
import tkinter as tk
from tkinter import messagebox
import re
import threading
# 全局变量,用于控制消息发送的循环
is_sending = False
def get_msg():
"""获取输入框中的消息,每条消息用逗号或句号分开"""
contents = input_text.get("1.0", tk.END).strip()
return [msg for msg in re.split(r'[,,。;.]', contents) if msg]
def send(msg):
# 复制需要发送的内容到粘贴板
pyperclip.copy(msg)
# 模拟键盘 ctrl + v 粘贴内容
pyautogui.hotkey('ctrl', 'v')
# 发送消息
pyautogui.press('enter')
def send_msg_task():
global is_sending
is_sending = True
friend = friend_entry.get()
if not friend:
messagebox.showerror("错误", "请输入好友名称")
is_sending = False
return
try:
interval = float(interval_entry.get())
except ValueError:
messagebox.showerror("错误", "请输入有效的时间间隔(数字)")
is_sending = False
return
# Ctrl + alt + w 打开微信
pyautogui.hotkey('ctrl', 'alt', 'w')
# 搜索好友
pyautogui.hotkey('ctrl', 'f')
# 复制好友昵称到粘贴板
pyperclip.copy(friend)
# 模拟键盘 ctrl + v 粘贴
pyautogui.hotkey('ctrl', 'v')
time.sleep(1)
# 回车进入好友消息界面
pyautogui.press('enter')
# 一条一条发送消息
messages = get_msg()
if not messages:
messagebox.showerror("错误", "请输入要发送的消息")
is_sending = False
return
if repeat_var.get() == 1:
while is_sending:
for msg in messages:
if not is_sending:
break
send(msg)
# 每条消息间隔设置的时间
time.sleep(interval)
else:
for msg in messages:
if not is_sending:
break
send(msg)
time.sleep(interval)
is_sending = False
def send_msg():
# 创建并启动新线程执行消息发送任务
thread = threading.Thread(target=send_msg_task)
thread.start()
def stop_sending():
global is_sending
is_sending = False
# 创建主窗口
root = tk.Tk()
root.title("微信消息发送器")
root.geometry("400x500")
root.configure(bg="#f0f0f0")
# 设置字体
font_style = ("Arial", 10)
# 好友输入框
friend_frame = tk.Frame(root, bg="#f0f0f0")
friend_frame.pack(pady=10)
friend_label = tk.Label(friend_frame, text="好友名称:", bg="#f0f0f0", font=font_style)
friend_label.pack(side=tk.LEFT)
friend_entry = tk.Entry(friend_frame, width=30, font=font_style)
friend_entry.pack(side=tk.LEFT, padx=10)
# 消息输入框
input_frame = tk.Frame(root, bg="#f0f0f0")
input_frame.pack(pady=10)
input_label = tk.Label(input_frame, text="要发送的消息(每条消息用逗号或句号分开):", bg="#f0f0f0", font=font_style)
input_label.pack(side=tk.TOP)
input_text = tk.Text(input_frame, width=35, height=5, font=font_style)
input_text.pack(side=tk.TOP, padx=10)
# 时间间隔输入框
interval_frame = tk.Frame(root, bg="#f0f0f0")
interval_frame.pack(pady=10)
interval_label = tk.Label(interval_frame, text="每条消息时间间隔(秒):", bg="#f0f0f0", font=font_style)
interval_label.pack(side=tk.LEFT)
interval_entry = tk.Entry(interval_frame, width=10, font=font_style)
interval_entry.pack(side=tk.LEFT, padx=10)
# 单选框选择是否重复发送
repeat_var = tk.IntVar()
repeat_frame = tk.Frame(root, bg="#f0f0f0")
repeat_frame.pack(pady=10)
tk.Radiobutton(repeat_frame, text="重复发送", variable=repeat_var, value=1, bg="#f0f0f0", font=font_style).pack(
side=tk.LEFT)
tk.Radiobutton(repeat_frame, text="仅发送一次", variable=repeat_var, value=0, bg="#f0f0f0", font=font_style).pack(
side=tk.LEFT)
# 发送按钮
send_button = tk.Button(root, text="发送消息", command=send_msg, font=font_style, bg="#4CAF50", fg="white", padx=20,
pady=5)
send_button.pack(pady=10)
# 停止按钮
stop_button = tk.Button(root, text="停止发送", command=stop_sending, font=font_style, bg="#FF5722", fg="white", padx=20,
pady=5)
stop_button.pack(pady=10)
# 运行主循环
root.mainloop()