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でWeChatのマルチオープンを実現するための1行のコード

コードを実行する前に、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 という関数を作成し、ファイルのドラッグアンドドロップイベントを処理するために使用します。ユーザーがファイルをウィンドウにドラッグアンドドロップすると、この関数はテキストボックスの内容をクリアし、ドラッグアンドドロップされたファイルを 1 つずつ処理します。各ファイルに対して、ファイルパスを 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. デスクトップ上の WeChat アイコンをドラッグアンドドロップします。起動するプログラムのショートカットファイルをウィンドウにドラッグアンドドロップすると、ファイルパスがテキストボックスに表示されます。

  2. 起動数量を入力します。数量入力ボックスに起動したいプログラムの数量を入力します。デフォルトは 2 です。起動ボタンをクリックすると、指定した数量の WeChat が起動します。

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