电脑上python实现多开微信

电脑上多开微信登录,需要点技巧,用python实现多开微信,使用tkinter的GUI界面,使体验更友好点
以下是 多开微信.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import pickle
import subprocess
import tkinter as tk
import tkinter.messagebox
import tkinter.filedialog


"""
author: chenluochun
date: 2020-06-21
"""


window = tk.Tk()

window.title('多开微信配置')

window.geometry('400x300')

var_name = tk.StringVar()
var_name.set(r"D:\Program Files (x86)\Tencent\WeChat")
tk.Label(window, text='微信安装路径:', font=('Arial', 10)).place(x=10, y=135)
entry_usr_name = tk.Entry(window, textvariable=var_name, font=('Arial', 13))
entry_usr_name.place(x=120, y=135)

BASE_DIR = os.path.abspath(os.path.dirname(__file__))
if "dist" in BASE_DIR:
    BASE_DIR = BASE_DIR.rstrip("dist")

r_path = var_name.get()
cf_path = os.path.join(r_path, "config_info.pickle")

close_flag = tk.StringVar()

config_info = {}
try:
    with open(cf_path, 'rb') as usr_file:
        config_info = pickle.load(usr_file)
        if config_info.get("w_path") == "ok":
            r_path = config_info["r_path"]
            close_flag.set("ok")
except FileNotFoundError:
    try:
        if os.path.exists(r_path):
            with open(cf_path, 'wb') as usr_file:
                config_info = {'w_path': 'error'}
                close_flag.set("error")
                pickle.dump(config_info, usr_file)
    except Exception as e:
        tkinter.messagebox.showinfo("提示:", str(e) + "--" + BASE_DIR)


def get_path():
    f_path = tkinter.filedialog.askdirectory()
    if f_path:
        var_name.set(f_path)


def exc_file(r_path):
    try:
        cmd1 = "PATH %s" % r_path
        cmd2 = "start WeChat.exe&WeChat.exe"
        cmd = cmd1 + "&" + cmd2
        f = subprocess.Popen(args=cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                             stdin=subprocess.DEVNULL)
        window.destroy()
    except Exception as e:
        tkinter.messagebox.showinfo("提示:", "启动失败 %s" % e)


def config_path():
    r_path = var_name.get()
    w_path = os.path.join(r_path, "WeChat.exe")
    if os.path.exists(w_path):
        cf_path = os.path.join(r_path, "config_info.pickle")
        with open(cf_path, 'wb') as usr_file:
            config_info['w_path'] = "ok"
            config_info["r_path"] = r_path
            pickle.dump(config_info, usr_file)
        exc_file(r_path=r_path)
    else:
        tkinter.messagebox.showinfo("提示:", "请正确设置微信的安装路径")


btn_login = tk.Button(window, text='选择', command=get_path)
btn_login.place(x=320, y=132)
btn_sign_up = tk.Button(window, text='确定', command=config_path)
btn_sign_up.place(x=170, y=180)

if close_flag.get() == "ok":
    exc_file(r_path=r_path)

window.mainloop()

将ico图片保存在python文件的同级目录下
使用pyinstaller打包成window的可执行文件(.exe)
pyinstaller -F ./多开微信.py --noconsole -i wehat.ico
打包成功后将生产 多开微信.exe
电脑上python实现多开微信_第1张图片

你可能感兴趣的:(电脑上python实现多开微信)