朋友办公用的电脑需要多开微信,但百度搜索一番,这类工具大多开始收费或者自带各种捆绑,求助于我,闲暇之余做了一个简单的工具,给他使用,在这里分享一下。
本文默认读者有Python基础知识,能自行阅读理解代码含义。并提供打包后的EXE文件下载。
原创首发CSDN文章,转载请注明来源。
#pyside6创建的ui编译成的模块文件,主程序代码下方代码为模块文件代码
from Ui_vx import Ui_vx
from PySide6.QtWidgets import QApplication,QWidget
import os
import json
class MyWindow(QWidget,Ui_vx):
def __init__(self):
super().__init__()
self.setupUi(self)
#当前工作目录设为当前程序所在目录
os.chdir(os.path.dirname(__file__))
self.bind()#绑定页面部件信号
self.load_default_config()#加载默认配置
def load_default_config(self):
'''
加载默认配置
'''
try:
with open('config.json','r') as file:
config_dict = json.load(file)
self.address_lineEdit.setText(config_dict['address'])
self.number_spinBox.setValue(config_dict['number'])
self.address = config_dict['address']
self.number = config_dict['number']
except:
config_dict={}
config_dict.update({'address':'','number':2})
with open('config.json','w') as f:
json.dump(config_dict,f,ensure_ascii=False,indent=4)
def bind(self):
'''
绑定页面配置文件
'''
self.address_lineEdit.textChanged.connect(self.change_config)
self.number_spinBox.valueChanged.connect(self.change_config)
self.start_btn.clicked.connect(self.start_vx)
def change_config(self):
'''
配置改变时的槽函数
'''
self.config_dict = {}
self.address = self.address_lineEdit.text()
self.number = self.number_spinBox.value()
self.config_dict.update({'address':self.address,'number':self.number})
with open('config.json' ,'w') as file:
json.dump(self.config_dict,file,ensure_ascii=False,indent=4)
def start_vx(self):
'''
启动微信客户端
'''
for _ in range(self.number):
os.system(f'start "" "{self.address}"')
if __name__ == '__main__':
app = QApplication([])
window = MyWindow()
window.show()
app.exec()
UI模块文件代码
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'vx.ui'
##
## Created by: Qt User Interface Compiler version 6.5.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QLabel, QLineEdit, QPushButton,
QSizePolicy, QSpinBox, QWidget)
class Ui_vx(object):
def setupUi(self, vx):
if not vx.objectName():
vx.setObjectName(u"vx")
vx.resize(441, 156)
self.address_lineEdit = QLineEdit(vx)
self.address_lineEdit.setObjectName(u"address_lineEdit")
self.address_lineEdit.setGeometry(QRect(100, 20, 301, 21))
self.label = QLabel(vx)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(40, 20, 54, 16))
self.label_2 = QLabel(vx)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(40, 70, 54, 16))
self.start_btn = QPushButton(vx)
self.start_btn.setObjectName(u"start_btn")
self.start_btn.setGeometry(QRect(170, 70, 231, 24))
self.label_3 = QLabel(vx)
self.label_3.setObjectName(u"label_3")
self.label_3.setGeometry(QRect(10, 110, 421, 20))
self.number_spinBox = QSpinBox(vx)
self.number_spinBox.setObjectName(u"number_spinBox")
self.number_spinBox.setGeometry(QRect(100, 70, 42, 22))
self.number_spinBox.setMinimum(2)
self.number_spinBox.setMaximum(4)
self.label_4 = QLabel(vx)
self.label_4.setObjectName(u"label_4")
self.label_4.setGeometry(QRect(20, 130, 361, 20))
self.retranslateUi(vx)
QMetaObject.connectSlotsByName(vx)
# setupUi
def retranslateUi(self, vx):
vx.setWindowTitle(QCoreApplication.translate("vx", u"\u5fae\u4fe1\u5206\u8eab\u5de5\u5177(PC\u7248)", None))
self.label.setText(QCoreApplication.translate("vx", u"\u5fae\u4fe1\u5730\u5740", None))
self.label_2.setText(QCoreApplication.translate("vx", u"\u5f00\u542f\u6570\u91cf", None))
self.start_btn.setText(QCoreApplication.translate("vx", u"\u7acb\u5373\u542f\u7528", None))
self.label_3.setText(QCoreApplication.translate("vx", u"*\u9996\u6b21\u4f7f\u7528\u5f55\u5165\u5fae\u4fe1\u5730\u5740\u5230\u5730\u5740\u680f\u540e,\u70b9\u51fb\u7acb\u5373\u542f\u7528\u3002\u4f7f\u7528\u672c\u5de5\u5177\u524d\u4e0d\u8981\u767b\u5f55\u5fae\u4fe1", None))
self.label_4.setText(QCoreApplication.translate("vx", u"\u8fc7\u591a\u7684\u5ba2\u6237\u7aef\u542f\u52a8\u53ef\u80fd\u4f1a\u9020\u6210\u5185\u5b58\u5d29\u6e83,\u672c\u7a0b\u5e8f\u6700\u9ad8\u9650\u5b9a4\u4e2a\u5ba2\u6237\u7aef", None))
# retranslateUi