软件功能:很简单,选数量,想开几个选几个
下载链接:https://caiyun.139.com/w/i/2oRh9PS0MG9mw
提取码:du5m
[Python] - import os
- import subprocess
- import sys
- import tkinter as tk
- from tkinter import messagebox, filedialog, ttk
- from pathlib import Path
- import time
- import psutil
- def resource_path(relative_path):
- try:
- base_path = sys._MEIPASS
- except Exception:
- base_path = os.path.abspath(".")
- return os.path.join(base_path, relative_path)
- def open_wechat(wechat_path: str, count: int):
- """启动指定数量的微信实例"""
- if not os.path.exists(wechat_path):
- raise FileNotFoundError(f"未找到微信程序,路径不存在:{wechat_path}")
- for _ in range(count):
- subprocess.Popen([wechat_path])
- def browse_path():
- """浏览并选择微信路径"""
- path = filedialog.askopenfilename(
- title="选择微信程序",
- filetypes=[("微信程序", "WeChat.exe"), ("所有文件", "*.*")]
- )
- if path:
- path_entry.delete(0, tk.END)
- path_entry.insert(0, path)
- def check_wechat_running():
- """检查微信是否已成功启动"""
- for proc in psutil.process_iter(['name']):
- if 'WeChat.exe' in proc.info['name']:
- return True
- return False
- def start_wechat():
- """开始启动微信"""
- try:
- wechat_path = path_entry.get().strip()
- count = int(count_combobox.get())
- if not wechat_path:
- status_label.config(text="请输入微信路径", fg="red")
- return
- if count < 1:
- status_label.config(text="数量必须大于0", fg="red")
- return
- open_wechat(wechat_path, count)
- status_label.config(text=f"正在启动微信...", fg="blue")
- # 延迟检查微信是否启动成功
- root.after(1000, lambda: check_and_close())
- except FileNotFoundError:
- status_label.config(text="微信程序路径不存在", fg="red")
- except Exception as e:
- status_label.config(text=f"启动失败: {str(e)}", fg="red")
- def check_and_close():
- """检查微信是否启动成功,成功则关闭工具"""
- if check_wechat_running():
- root.destroy() # 关闭工具窗口
- else:
- # 最多尝试5次
- if not hasattr(check_and_close, 'attempts'):
- check_and_close.attempts = 0
- check_and_close.attempts += 1
- if check_and_close.attempts < 5:
- # 继续检查
- root.after(1000, check_and_close)
- else:
- # 超时显示错误
- status_label.config(text="启动超时,请手动检查", fg="red")
- check_and_close.attempts = 0 # 重置计数器
- # 创建主窗口
- root = tk.Tk()
- root.title("微信多开工具")
- root.geometry("500x200")
- root.resizable(False, False)
- # 设置窗口居中
- window_width = 500
- window_height = 200
- screen_width = root.winfo_screenwidth()
- screen_height = root.winfo_screenheight()
- x = (screen_width - window_width) // 2
- y = (screen_height - window_height) // 2
- root.geometry(f"{window_width}x{window_height}+{x}+{y}")
- # 设置窗口图标
- try:
- icon_path = resource_path("text.ico") # 使用资源路径函数获取图标
- if os.path.exists(icon_path):
- root.iconbitmap(icon_path)
- except Exception as e:
- print(f"加载图标失败: {e}")
- # 创建标题标签
- title_label = tk.Label(root, text="微信多开工具", font=("Microsoft YaHei", 16, "bold"))
- title_label.pack(pady=10)
- # 创建路径输入框和浏览按钮
- path_frame = tk.Frame(root)
- path_frame.pack(fill=tk.X, padx=20, pady=5)
- path_label = tk.Label(path_frame, text="微信路径:", width=10)
- path_label.pack(side=tk.LEFT)
- path_entry = tk.Entry(path_frame)
- path_entry.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=5)
- browse_button = tk.Button(path_frame, text="浏览...", command=browse_path)
- browse_button.pack(side=tk.LEFT)
- # 创建数量选择下拉框和状态显示
- count_frame = tk.Frame(root)
- count_frame.pack(fill=tk.X, padx=20, pady=5)
- count_label = tk.Label(count_frame, text="实例数量:", width=10)
- count_label.pack(side=tk.LEFT)
- # 创建下拉选择框,选项为1-9
- count_combobox = ttk.Combobox(count_frame, values=list(range(2, 11)), width=5)
- count_combobox.current(0) # 默认选择1
- count_combobox.pack(side=tk.LEFT, padx=5)
- # 添加状态显示标签
- status_label = tk.Label(count_frame, text="", fg="green")
- status_label.pack(side=tk.LEFT, padx=10)
- # 创建启动按钮
- start_button = tk.Button(root, text="启动微信", command=start_wechat, bg="#4CAF50", fg="white", height=2)
- start_button.pack(pady=20, fill=tk.X, padx=100)
- # 尝试设置默认路径
- default_wechat_path = Path(r"C:\Program Files\Tencent\WeChat\WeChat.exe")
- if default_wechat_path.exists():
- path_entry.insert(0, str(default_wechat_path))
- # 运行主循环
- root.mainloop()
复制代码
|