通过python实现一个QQ自动点赞

在这篇文章中,我们将介绍如何使用Python编写一个自动点赞控制界面。这个界面可以帮助用户轻松地启动和停止自动点赞功能,同时还可以返回主界面。我们将使用tkinter库来创建GUI界面,并使用pyautogui库来实现鼠标操作。

首先,通过pip install +我们需要导入所需的库:

import os
import threading
import time
import tkinter
from tkinter import *
from tkinter.messagebox import askyesno

import aircv as ac
import pyautogui

接下来,我们创建一个名为MY_GUI_1的类,用于实现自动点赞控制界面的功能: 

class MY_GUI_1:
    def __init__(self):
        self.stop_eve = True
        self.init_de = tkinter.Tk()
        self.init_de.title('自动点赞控制界面')
        self.init_de.resizable(False, False)
        self.init_de.attributes('-topmost', True)  # 让窗口始终在最前面
        self.init_de.geometry('150x40')  # 背景
        self.init_det()

实现自动点赞功能的主要逻辑。首先,我们让程序等待5秒钟,然后将鼠标移动到指定位置并点击。接着,我们进入一个循环,每隔一段时间检查是否需要停止自动点赞。如果需要停止,我们就跳出循环;否则,继续执行begin方法。最后,我们弹出一个提示框,告诉用户程序已经执行完毕。

    def init_det1(self):
        time.sleep(5)
        pyautogui.moveTo(20, 40)
        pyautogui.click(clicks=1, interval=0.2)
        time.sleep(1)
        pyautogui.moveTo(340, 80)
        pyautogui.click(clicks=1, interval=0.2)
        start_time = time.time()  # 获取当前时间
        while True:
            if time.time() - start_time > 600:
                break
            if self.stop_eve:
                self.begin()
            else:
                break

        askyesno(title='提示', message='程序执行完毕')

begin方法是实现自动点赞的具体逻辑。首先,我们让程序等待1秒钟,然后截取屏幕。接着,我们查找点赞图标的位置,并将结果保存在pos变量中。然后,我们遍历pos中的每个元素,将鼠标移动到对应位置并点击。最后,我们滚动鼠标以查看更多内容。

    # 获取赞所在的位置
    def mouseposs(self, img1, img2):
        points = []
        for i in ac.find_all_template(ac.imread(img1), ac.imread(img2), 0.70):
            points.append((i['result']))
        return points

需要的图片:

完整代码:

import os
import threading
import time
import tkinter
from tkinter import *
from tkinter.messagebox import askyesno

import aircv as ac
import pyautogui


class MY_GUI_1:
    def __init__(self):
        self.stop_eve = True
        self.init_de = tkinter.Tk()
        self.init_de.title('自动点赞控制界面')
        self.init_de.resizable(False, False)
        self.init_de.attributes('-topmost', True)  # 让窗口始终在最前面
        self.init_de.geometry('150x40')  # 背景
        self.init_det()

    def init_det(self):
        # 按钮
        self.anniu = Button(self.init_de, text='启动', width='15', command=self.kais1)
        self.anniu.place(x=0, y=0, width=50)
        self.anniu = Button(self.init_de, text='停止', width='15', command=self.tizi)
        self.anniu.place(x=50, y=0, width=50)
        self.anniu = Button(self.init_de, text='返回', width='15', command=self.ticu)
        self.anniu.place(x=100, y=0, width=50)

    def init_det1(self):
        time.sleep(5)
        pyautogui.moveTo(20, 40)
        pyautogui.click(clicks=1, interval=0.2)
        time.sleep(1)
        pyautogui.moveTo(340, 80)
        pyautogui.click(clicks=1, interval=0.2)
        start_time = time.time()  # 获取当前时间
        while True:
            if time.time() - start_time > 600:
                break
            if self.stop_eve:
                self.begin()
            else:
                break

        askyesno(title='提示', message='程序执行完毕')

    def kais1(self):
        self.stop_eve = True
        askyesno(title='提示', message='程序开始执行,请最大化QQ页面')
        self.T = threading.Thread(target=self.init_det1)  # 多线程
        self.T.setDaemon(True)  # 线程守护,即主进程结束后,此线程也结束。否则主进程结束子进程不结束
        self.T.start()  # 启动

    def tizi(self):
        self.stop_eve = False

    def begin(self):
        # 截屏
        time.sleep(1)
        img1 = pyautogui.screenshot()
        if os.path.exists('1.png'):  # 如果文件存在
            os.remove('1.png')
        img1.save('1.png')
        pos = self.mouseposs('1.png', 'dia.png')
        for i in pos[:]:
            if i[0] != pos[0][0]:
                pos.remove(i)
        print(pos)

        # 点击
        for i in pos:
            pyautogui.moveTo(i[0], i[1])
            pyautogui.click(clicks=20, interval=0.2)
            time.sleep(1)

        # 滚动鼠标
        pyautogui.scroll(-200, x=100, y=100)

    # 获取赞所在的位置
    def mouseposs(self, img1, img2):
        points = []
        for i in ac.find_all_template(ac.imread(img1), ac.imread(img2), 0.70):
            points.append((i['result']))
        return points

    def ticu(self):
        self.init_de.destroy()
        from main import on_closing
        on_closing()


if __name__ == "__main__":
    st = MY_GUI_1()
    st.init_de.mainloop()

  • 12
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骇客黑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值