源代码:
from tkinter import *
import win32gui
import win32con
import win32clipboard as w
LOG_LINE_NUM = 0
class Play():
def __init__(self, init_window_name):
self.init_window_name = init_window_name
def set_init_window(self): #构建框架
self.init_window_name.title("qq消息发送器")
self.init_window_name.geometry("730x120+10+10")
self.init_window_name.attributes("-alpha", 1) # 虚化 值越小虚化程度越高
# 标签
self.init_data_label = Label(self.init_window_name, text="输入要发送消息者")
self.init_data_label.grid(row=0, column=0)
self.name_data_label = Label(self.init_window_name, text="要发送内容")
self.name_data_label.grid(row=0, column=12)
self.log_label = Label(self.init_window_name, text="@ 2020版权所有 https://blog.51cto.com/982439641")
self.log_label.grid(row=12, column=0)
# 文本框
self.init_data_Text = Text(self.init_window_name, width=45, height=5) # 原始数据录入框
self.init_data_Text.grid(row=1, column=0, rowspan=1, columnspan=1)
self.log_data_Text = Text(self.init_window_name, width=45, height=5) # 日志框
self.log_data_Text.grid(row=1, column=8, columnspan=10)
self.str_command = Button(self.init_window_name, text="发送100次", bg="lightblue", width=10,
command=self.Send) # 调用内部方法 加()为直接调用
self.str_command.grid(row=1, column=6)
def Send(self):
for i in range(0,10):
a=self.init_data_Text.get(1.0, END).strip().replace("\n", "").encode()
b = self.log_data_Text.get(1.0, END).strip().replace("\n", "").encode()
receiver=str(a,encoding="utf-8")
msg=str(b,encoding="utf-8")
###############################发送qq消息使用下面几行#########
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_UNICODETEXT, msg)
w.CloseClipboard()
qq = win32gui.FindWindow(None, receiver)
win32gui.SendMessage(qq, win32con.WM_PASTE, 0, 0)
win32gui.SendMessage(qq, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
###############################done#########################
if __name__=="__main__":
init_window = Tk()
Play(init_window).set_init_window()
init_window.mainloop()