在运行代码之前,下载 wftools 这个库的命令如下:
pip install wftools
安裝完畢後,使用 wftools 模組
import wftools
soft_path = r"D:\ 微信 \WeChat\WeChat.exe"
wftools.open_soft(soft_path=soft_path, num=2)
soft_path 這裡,改成自己電腦上 WeChat.exe 的存儲位置,num 這裡,改成你要打開幾個微信。
圖形界面版本:
import tkinter as tk
import windnd
import win32com.client
import wftools
def handle_drag(files):
text.delete("1.0", "end")
for file in files:
file = file.decode("gbk")
target_path = get_shortcut_target(file)
text.insert("insert", target_path + "\n")
def get_shortcut_target(path):
shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut(path)
target_path = shortcut.Targetpath
return target_path
def start_program():
quantity = int(quantity_entry.get())
soft_path = text.get("1.0", "end").strip()
wftools.open_soft(soft_path=soft_path, num=quantity)
root = tk.Tk()
root.title("微信多開小工具")
root.geometry("410x200")
root.resizable(False, False) # 固定窗口大小
text = tk.Text(root, width=60, height=3, font=("Arial", 12))
text.pack(padx=10, pady=10)
windnd.hook_dropfiles(root, func=handle_drag)
quantity_label = tk.Label(root, text="啟動數量:", font=("Arial", 12))
quantity_label.pack()
quantity_entry = tk.Entry(root, font=("Arial", 12))
quantity_entry.insert(0, "2")
quantity_entry.pack()
start_button = tk.Button(root, text="啟動", command=start_program, font=("Arial", 12), bg="lightblue", fg="white")
start_button.pack(pady=10)
root.mainloop()
首先,我們創建了一個名為 handle_drag 的函數,用於處理文件拖放事件。當用戶拖放文件到窗口時,該函數會清空文本框中的內容,並逐個處理拖放的文件。對於每個文件,它會將文件路徑解碼為 GBK 編碼,並使用 get_shortcut_target 函數獲取快捷方式的目標路徑。然後,它將目標路徑插入到文本框中。
接下來,我們定義了一個名為 get_shortcut_target 的函數,用於獲取快捷方式的目標路徑。它使用 win32com 庫創建一個 WScript.Shell 對象,並通過該對象的 CreateShortcut 方法來獲取快捷方式的目標路徑。
然後,我們定義了一個名為 start_program 的函數,用於啟動程序。它首先從輸入框中獲取用戶輸入的啟動數量,並從文本框中獲取程序路徑。然後,它調用 wftools 庫中的 open_soft 函數,傳遞程序路徑和啟動數量作為參數,以啟動指定數量的程序。
接下來,我們創建了一個 Tkinter 的根窗口對象,並設置了窗口的標題、大小和不可調整大小的屬性。
然後,我們創建了一個文本框對象,用於顯示文件路徑。
接著,我們使用 windnd 庫的 hook_dropfiles 函數將文件拖放事件與 handle_drag 函數關聯起來。
然後,我們創建了一個標籤和一個輸入框,用於用戶輸入啟動數量。
最後,我們創建了一個按鈕,用於觸發 start_program 函數。
最後,我們調用 root.mainloop () 來啟動程序的事件循環,使 GUI 界面能夠響應用戶的操作。
使用方法:
1,拖放桌面微信圖標:將需要啟動的程序的快捷方式文件拖放到窗口中,文件路徑會顯示在文本框中。
2,輸入啟動數量:在數量輸入框中輸入你想要啟動的程序數量。默認為 2。點擊啟動即可實現多開微信功能。