2022-5-25 使用 tkinter ,pyautogui,pyperclip 制作了控制电脑微信自动发消息程序
带注解
import time
import tkinter as tk
from typing import KeysView
import pyautogui as py
import pyperclip as pc
import time
#自定义函数fs()
def fs():
x=0
while x<999:
n=0
mc=t1.get('0.0','end') #获取用户名赋值给mc
nr=t2.get('0.0','end') #获取内容赋值给nr
cs=t3.get('0.0','end') #获取次数赋值给mccs
py.hotkey('ctrl','alt','w') #将 ctrl +alt +w 按键顺序按下,再逆序释放 打开微信窗口
time.sleep(1) #暂停1秒
py.hotkey('ctrl','f') #将 ctrl +f 按键顺序按下,再逆序释放 微信查找
pc.copy(mc) #复制用户名
py.hotkey('ctrl','v') #将 ctrl + v按键顺序按下,再逆序释放 微信粘贴
time.sleep(1)
py.hotkey('enter') #将 回车按键顺序按下 选择用户
time.sleep(1)
while n<int(cs): #次数循环,小于用户设置次数开始
pc.copy(nr) #复制消息
py.hotkey('ctrl','v') #将 ctrl + v按键顺序按下,再逆序释放 微信粘贴消息
py.hotkey('enter')#将 回车按键顺序按下 发送消息
n=n+1 #循环递进
time.sleep(5) #暂停5秒
sr=input('请输入退出或回车键继续') #信息交互,用户输入
if sr=='退出':
x=1000
jm=tk.Tk() #新建win窗口
jm.title('信息发送') #窗口标题
jm.geometry('500x500') #窗口大小
an=tk.Button(text='开始',width=10,height=1,command=fs).place(x=180,y=250) #新建按钮,点击执行fs函数
t1=tk.Text(width=35,height=2);t1.place(x=167,y=50) #设置窗口的用户名input
t1.get('0.0','end')#获取用户名
t2=tk.Text(width=35,height=2);t2.place(x=167,y=125)#设置窗口的消息内容input
t2.get('0.0','end')#获取消息内容
t3=tk.Text(width=35,height=2);t3.place(x=167,y=200)#设置窗口的次数input
t3.get('0.0','end')#获取次数
l1=tk.Label(text='用户名');l1.place(x=70,y=55) #设置用户名label
l2=tk.Label(text='内容');l2.place(x=70,y=130)#设置内容label
l3=tk.Label(text='次数');l3.place(x=70,y=205)#设置次数label
jm.mainloop()# 进入等待与处理窗口事件