Python定时点击桌面程序,可修改点击间隔

import pyautogui
import tkinter as tk

class Clicker:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("桌面点击程序")
        self.root.geometry("300x150")

        self.interval = tk.StringVar()
        self.interval.set("10")

        self.interval_label = tk.Label(self.root, text="间隔时间(秒):")
        self.interval_label.grid(row=0, column=0)

        self.interval_entry = tk.Entry(self.root, textvariable=self.interval)
        self.interval_entry.grid(row=0, column=1)

        self.start_button = tk.Button(self.root, text="开始", command=self.start_clicking)
        self.start_button.grid(row=1, column=0)

        self.stop_button = tk.Button(self.root, text="停止", command=self.stop_clicking, state=tk.DISABLED)
        self.stop_button.grid(row=1, column=1)

        self.root.mainloop()

    def start_clicking(self):
        self.start_button.config(state=tk.DISABLED)
        self.stop_button.config(state=tk.NORMAL)
        self.interval_entry.config(state=tk.DISABLED)
        self.clicking = True
        self.click()

    def stop_clicking(self):
        self.clicking = False
        self.start_button.config(state=tk.NORMAL)
        self.stop_button.config(state=tk.DISABLED)
        self.interval_entry.config(state=tk.NORMAL)

    def click(self):
        if self.clicking:
            pyautogui.click(pyautogui.size()[0]/2, pyautogui.size()[1]/2)
            #print("已点击", pyautogui.position())
            self.root.after(int(self.interval.get()) * 1000, self.click)

Clicker()

 

posted @ 2023-04-20 17:50  ~清风煮酒~  阅读(146)  评论(0编辑  收藏  举报