前言

有几个微信需要多开登录,每次都要按回车点击微信多开。把握不住,老是会开很多个。用python实现多开,精准控制需要打开的数量,但是打开前先要关闭所有微信。

运行图片:

![image-20250421215900582](./assets/image-20250421215900582.png)

源码

import tkinter as tk
import subprocess
import os
import time
from tkinter import messagebox, ttk


class WeChatMultiOpener:
    def __init__(self, root):
        self.root = root
        self.root.title("微信多开器")
        self.root.geometry("300x200")
        self.root.resizable(False, False)

        # 设置界面
        self.setup_ui()

    def setup_ui(self):
        # 主框架
        main_frame = tk.Frame(self.root, padx=20, pady=20)
        main_frame.pack(fill=tk.BOTH, expand=True)

        # 标题标签
        title_label = tk.Label(main_frame, text="微信多开工具", font=("Arial", 14, "bold"))
        title_label.pack(pady=10)

        # 数量选择框架
        count_frame = tk.Frame(main_frame)
        count_frame.pack(pady=10, fill=tk.X)

        # 数量标签
        count_label = tk.Label(count_frame, text="打开数量:")
        count_label.pack(side=tk.LEFT, padx=(0, 5))

        # 数量输入框
        self.count_var = tk.StringVar(value="2")
        count_spinbox = ttk.Spinbox(
            count_frame,
            from_=1,
            to=10,
            width=5,
            textvariable=self.count_var
        )
        count_spinbox.pack(side=tk.LEFT)

        # 按钮框架
        button_frame = tk.Frame(main_frame)
        button_frame.pack(pady=10)

        # 打开微信按钮
        open_button = tk.Button(button_frame, text="打开微信", width=12,
                                command=self.open_multiple_wechat, bg="#1aad19", fg="white")
        open_button.pack(side=tk.LEFT, padx=5)

        # 关闭所有微信按钮
        close_button = tk.Button(button_frame, text="关闭所有微信", width=12,
                                 command=self.close_all_wechat)
        close_button.pack(side=tk.LEFT, padx=5)

        # 状态标签
        self.status_var = tk.StringVar(value="就绪")
        status_label = tk.Label(main_frame, textvariable=self.status_var, fg="gray")
        status_label.pack(pady=(10, 0))

    def open_multiple_wechat(self):
        try:
            # 获取用户输入的数量
            count_text = self.count_var.get().strip()

            try:
                count = int(count_text)
                if count < 1 or count > 10:
                    messagebox.showwarning("警告", "请输入1-10之间的数字")
                    return
            except ValueError:
                messagebox.showwarning("警告", "请输入有效的数字")
                return
            wechat_path = r"C:\Program Files\Tencent\WeChat\WeChat.exe"

            # 检查路径是否存在
            if not os.path.exists(wechat_path):
                print("未找到微信程序,请检查安装路径")
                return

            # 更新状态
            self.status_var.set(f"正在打开 {count} 个微信实例...")
            self.root.update()

            # 打开指定数量的微信
            for i in range(0,count):
                # 使用命令行参数启动第二个微信实例
                self. open_multiple()
                # 稍微延迟,避免同时启动太多实例

            self.status_var.set(f"已成功打开 {count} 个微信实例")

        except Exception as e:
            self.status_var.set("操作失败")
            messagebox.showerror("错误", f"启动微信失败: {str(e)}")

    def open_multiple(self):
        # 微信安装路径,请根据实际情况修改
        wechat_path = r"C:\Program Files\Tencent\WeChat\WeChat.exe"

        # 检查路径是否存在
        if not os.path.exists(wechat_path):
            print("未找到微信程序,请检查安装路径")
            return
        # 使用命令行参数启动第二个微信实例
        subprocess.Popen([wechat_path, "/multi"])

    def close_all_wechat(self):
        try:
            self.status_var.set("正在关闭所有微信...")
            self.root.update()

            subprocess.run("taskkill /f /im WeChat.exe", shell=True)

            self.status_var.set("已关闭所有微信实例")
        except Exception as e:
            self.status_var.set("操作失败")
            messagebox.showerror("错误", f"关闭微信失败: {str(e)}")


if __name__ == "__main__":
    root = tk.Tk()
    app = WeChatMultiOpener(root)
    root.mainloop()

写在最后

希望能够帮到你们,有需要的朋友也可以私信后台,找我要打包好的程序直接运行。

标签: none