banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

Pythonの1行のコードでWeChatのマルチオープンを実現する

コードを実行する前に、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 を開きたい WeChat の数に変更します。

グラフィカルなバージョン:

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 という関数を定義しました。この関数はプログラムを起動するために使用されます。まず、quantity_entry からユーザーが入力した起動数量を取得し、text からプログラムのパスを取得します。その後、wftools ライブラリの open_soft 関数を呼び出し、プログラムのパスと起動数量を引数として指定して、指定された数量のプログラムを起動します。

次に、Tkinter のルートウィンドウオブジェクトを作成し、タイトル、サイズ、サイズ変更不可の属性を設定しました。

次に、ファイルパスを表示するためのテキストボックスオブジェクトを作成しました。

その後、windnd ライブラリの hook_dropfiles 関数を使用してファイルのドラッグアンドドロップイベントを handle_drag 関数に関連付けました。

その後、ユーザーが起動数量を入力するためのラベルとエントリーボックスを作成しました。

最後に、start_program 関数をトリガーするボタンを作成しました。

最後に、root.mainloop () を呼び出してプログラムのイベントループを開始し、GUI インターフェースがユーザーの操作に応答できるようにしました。

使用方法:

  1. デスクトップの WeChat アイコンをドラッグアンドドロップします:起動するプログラムのショートカットファイルをウィンドウにドラッグアンドドロップすると、ファイルのパスがテキストボックスに表示されます。

  2. 起動数量を入力します:数量の入力ボックスに起動するプログラムの数量を入力します。デフォルトは 2 です。起動をクリックすると、WeChat を複数起動する機能が実現されます。

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。