统信系统小程序(二)连点程序。更改了库才实现pyinstaller打包成功
·
# -*- coding: utf-8 -*- ''' 免费连点程序,可以任意修改源码。例如默认值20秒,可以改为其他时间。 Python使用pyautogui 会使用PYQT,使用pyinstall打包会提示存在多个邦本的PQt。卸载了PyQt5和SIP仍然是打包不成功,更改了功能更少了的pynput才成功不过不支持鼠标中键了。 使用 pytesseract模块的程序也是这个原因打包不成功,目前还没好的解决办法。 ''' import tkinter as tk from tkinter import ttk import threading import time from pynput import mouse, keyboard class AutoClickerApp: def __init__(self, root): self.root = root self.root.title("连点器") self.root.geometry("250x280") # 调整高度以容纳新行 self.root.configure(bg="#ccffcc") # 淡绿色背景 # 控制变量 self.interval = tk.StringVar(value="20") # 默认间隔20秒 self.click_count = tk.StringVar(value="500") # 默认次数50次 self.mouse_or_key = tk.StringVar(value="mouse") # 默认鼠标模式 self.key_value = tk.StringVar(value="left") # 默认左键点击 # 创建界面组件 self.create_widgets() # 运行状态标志 self.running = False def update_countdown(self, milliseconds): """更新倒计时显示""" self.countdown_label.config(text=f"点击倒计时: {milliseconds}ms") def create_widgets(self): # 主框架 main_frame = tk.Frame(self.root, bg="#ccffcc") main_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=20) # 间隔输入 interval_label = tk.Label(main_frame, text="连点间隔(秒):", bg="#ccffcc", font=("fangsong ti", 12)) interval_label.grid(row=0, column=0, sticky="w", pady=5) interval_entry = tk.Entry(main_frame, textvariable=self.interval, font=("fangsong ti", 12), width=10) interval_entry.grid(row=0, column=1, pady=5, padx=(10, 0)) # 在现有间隔行下方添加倒计时显示行 self.countdown_label = tk.Label( main_frame, # 修复:使用正确的父框架 text="点击倒计时: 0ms",font=("fangsong ti", 12),fg="blue",bg="#ccffcc" # 添加背景色以匹配整体风格 ) self.countdown_label.grid(row=1, column=0, columnspan=2, pady=5) # 使用grid布局保持一致性 # 次数输入 (原第1行,现在是第2行) count_label = tk.Label(main_frame, text="连点次数:", bg="#ccffcc", font=("fangsong ti", 12)) count_label.grid(row=2, column=0, sticky="w", pady=5) count_entry = tk.Entry(main_frame, textvariable=self.click_count, font=("fangsong ti", 12), width=10) count_entry.grid(row=2, column=1, pady=5, padx=(10, 0)) # 模式选择 (原第2-3行,现在是第3-4行) mode_label = tk.Label(main_frame, text="连点模式:", bg="#ccffcc", font=("fangsong ti", 12)) mode_label.grid(row=3, column=0, sticky="w", pady=5) mouse_radio = tk.Radiobutton(main_frame, text="鼠标", variable=self.mouse_or_key, value="mouse", bg="#ccffcc", font=("fangsong ti", 12), command=self.on_mode_change) mouse_radio.grid(row=3, column=1, sticky="w", pady=5) key_radio = tk.Radiobutton(main_frame, text="键盘", variable=self.mouse_or_key, value="key", bg="#ccffcc", font=("fangsong ti", 12), command=self.on_mode_change) key_radio.grid(row=4, column=1, sticky="w", pady=5) # 键盘按键输入 (原第4行,现在是第5行) self.key_frame = tk.Frame(main_frame, bg="#ccffcc") self.key_frame.grid(row=5, column=0, columnspan=2, sticky="w", pady=5) self.key_label = tk.Label(self.key_frame, text="按键:", bg="#ccffcc", font=("fangsong ti", 12)) self.key_label.pack(side=tk.LEFT) # 预设按键下拉菜单 self.key_options = ttk.Combobox(self.key_frame, textvariable=self.key_value, font=("fangsong ti", 12), width=10) self.key_options['values'] = ('left', 'enter', 'space', 'esc', 'tab', 'delete', '1', '2', '3') self.key_options.set('left') self.key_options.pack(side=tk.LEFT, padx=(10, 0)) # 控制按钮框架 (原第5行,现在是第6行) button_frame = tk.Frame(main_frame, bg="#ccffcc") button_frame.grid(row=6, column=0, columnspan=2, pady=10) # 开始按钮 (浅绿色) self.start_button = tk.Button(button_frame, text="开始", bg="#90ee90", font=("fangsong ti", 12), command=self.start_clicking) self.start_button.pack(side=tk.LEFT, padx=10) # 结束按钮 (浅红色) self.stop_button = tk.Button(button_frame, text="结束", bg="#f08080", font=("fangsong ti", 12), command=self.stop_clicking) self.stop_button.pack(side=tk.LEFT, padx=10) def on_mode_change(self): """当模式改变时调用""" if self.mouse_or_key.get() == "mouse": self.key_options.set("left") else: self.key_options.set("enter") def start_clicking(self): """开始点击""" if not self.running: self.running = True threading.Thread(target=self.run_clicker, daemon=True).start() def stop_clicking(self): """结束点击""" self.running = False def run_clicker(self): """执行点击操作的线程函数""" try: interval = float(self.interval.get()) except ValueError: interval = 5.0 # 默认值 try: count = int(self.click_count.get()) except ValueError: count = 50 # 默认值 # 将间隔转换为毫秒用于倒计时显示 interval_ms = int(interval * 1000) for i in range(count): if not self.running: break # 更新倒计时显示 self.update_countdown(interval_ms) if self.mouse_or_key.get() == "mouse": # 鼠标点击 self.mouse_click() else: # 键盘按键 self.keyboard_press() # 倒计时更新 remaining_time = interval_ms while remaining_time > 0 and self.running: time.sleep(0.1) # 每100ms更新一次显示 remaining_time -= 100 if remaining_time > 0: self.update_countdown(remaining_time) # 完成后重置倒计时显示 if not self.running: self.update_countdown(0) else: self.running = False def mouse_click(self): """执行鼠标点击""" button = self.key_value.get() mouse_controller = mouse.Controller() if button == 'left': mouse_controller.click(mouse.Button.left) elif button == 'right': mouse_controller.click(mouse.Button.right) elif button == 'middle': mouse_controller.click(mouse.Button.middle) else: # 默认使用左键 mouse_controller.click(mouse.Button.left) def keyboard_press(self): """执行键盘按键""" key = self.key_value.get() keyboard_controller = keyboard.Controller() # 映射按键 key_map = { 'enter': keyboard.Key.enter, 'space': keyboard.Key.space, 'esc': keyboard.Key.esc, 'tab': keyboard.Key.tab, 'delete': keyboard.Key.delete, '1': '1', '2': '2', '3': '3', 'left': keyboard.Key.left, 'right': keyboard.Key.right, 'up': keyboard.Key.up, 'down': keyboard.Key.down } mapped_key = key_map.get(key, key) try: keyboard_controller.press(mapped_key) keyboard_controller.release(mapped_key) except Exception as e: print(f"按键 {key} 执行出错: {e}") if __name__ == "__main__": root = tk.Tk() app = AutoClickerApp(root) root.mainloop()
更多推荐
所有评论(0)