图形化界面代码
import tkinter as tk
from tkinter import messagebox
from weixin_send_message import Open_data
def send_messages():
# 发送信息的逻辑(这里省略)
recipient = entry_recipient.get()
message = entry_message.get()
count = int(entry_count.get())
print("recipient",recipient)
print("recipient", message)
print("recipient", count)
open = Open_data(recipient, message, count)
open.implement_data()
root.destroy()
# 创建主窗口
root = tk.Tk()
root.title("信息发送器")
root.geometry("500x500") # 设置窗口大小为500x500
# 创建输入框和标签
label_recipient = tk.Label(root, text="给谁发信息:", font=("Helvetica", 14))
label_recipient.pack(pady=10) # 添加垂直填充
entry_recipient = tk.Entry(root, font=("Helvetica", 14))
entry_recipient.pack(pady=10) # 添加垂直填充
label_message = tk.Label(root, text="发什么信息:", font=("Helvetica", 14))
label_message.pack(pady=10) # 添加垂直填充
entry_message = tk.Entry(root, font=("Helvetica", 14), width=20) # 设置宽度
entry_message.pack(pady=10) # 添加垂直填充
label_count = tk.Label(root, text="发几次:", font=("Helvetica", 14),width=20)
label_count.pack(pady=10) # 添加垂直填充
entry_count = tk.Entry(root, font=("Helvetica", 14), width=10) # 设置宽度以适应数字
entry_count.pack(pady=10) # 添加垂直填充
# 创建发送按钮并绑定send_messages函数
button_send = tk.Button(root, text="发送", font=("Helvetica", 10), width=10, height=2, command=send_messages)
button_send.pack(pady=20) # 添加垂直填充使按钮更突出
# 运行主循环
root.mainloop()
逻辑代码部分
import pyautogui
import time
import pyperclip
def click(image_path:str):
center = pyautogui.locateCenterOnScreen(image_path)
if center:
print(f"找到图像,中心坐标是:{center}")
pyautogui.click(center)
else:
print("未找到图像")
def click_one(image_path: str,x_data:int,y_data:int):
center = pyautogui.locateCenterOnScreen(image_path)
if center:
# 解包center元组
x, y = center
# 修改x和y的值各加10
new_x = x + x_data
new_y = y + y_data
# 打包成新的元组
new_center = (new_x, new_y)
print(f"找到图像1111,修改后的中心坐标是:{new_center}")
# 使用新的坐标进行点击
pyautogui.click(new_center)
else:
print("未找到图像")
import os
from lxml import html
import pyautogui
import pyperclip
import requests
from data_python.method.click_data import click,click_one,send_data_infor
import time
class Open_data:
def __init__(self,nickname,data:str,num:int):
self.soft_path = "D:/installSoft/wx/wxInstall/WeChat/WeChat.exe"
self.nickname=nickname
self.data=data
self.num=num
# 启动软件
def open_software(self):
try:
status = os.startfile(self.soft_path)
print("status:", status)
except FileNotFoundError:
print("路径不正确或未找到")
def search_Friend(self,nickname):
image_path="data/search.png"
center = pyautogui.locateCenterOnScreen(image_path)
time.sleep(1)
if center:
print(f"找到图像,中心坐标是:{center}")
pyautogui.click(center)
time.sleep(1) # 等待1秒
pyperclip.copy(nickname)
pyautogui.hotkey('ctrl', 'v')
else:
print("未找到图像")
def click_friend(self):
image_path="data/findFriend.png"
# click(image_path)
click_one(image_path,10,30)
# 点击好友发送信息的输入框
def send_data_infor(self):
time.sleep(1)
image_path = "data/input_infor.png"
center = pyautogui.locateCenterOnScreen(image_path)
time.sleep(2)
if center:
print(f"找到图像,中心坐标是:{center}")
pyautogui.click(center)
for item in range(0,self.num):
pyperclip.copy(self.data)
pyautogui.hotkey('ctrl', 'v')
image_path_send = "data/send.png"
image_path_send_only="data/only.png"
click_one(image_path_send_only,0,-200)
click(image_path_send)
else:
print("未找到图像")
def implement_data(self):
self.open_software()
time.sleep(0.5)
self.search_Friend(self.nickname)
# 点击好友
self.click_friend()
# 找到好友发送信息
self.send_data_infor()
if __name__ == '__main__':
open = Open_data('阿西木江','kobe',3)
open.implement_data()