小工具长相:
直接上代码:
# -*- coding:UTF-8 -*-
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import time
import itchat,time,re
from itchat.content import *
import threading
text1 = 'hello'
text2 = 'hello'
@itchat.msg_register([TEXT])
def text_reply(msg):
itchat.send((text1), msg['FromUserName'])
@itchat.msg_register([PICTURE,RECORDING,VIDEO,SHARING])
def other_reply(msg):
itchat.send((text2), msg['FromUserName'])
def startReply(name):
a = itchat.auto_login(hotReload=True)
print(a)
itchat.run()
def stopReply():
itchat.logout()
class FirstWindow(QWidget):
def __init__(self):
super(FirstWindow,self).__init__()
self.windowUI()
def closeEvent(self, event):
reply = QMessageBox.question(self, '提示',
"确定退出?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
stopReply()
QCoreApplication.instance().quit()
else:
event.ignore()
def windowUI(self):
self.setWindowTitle("wb")
self.textfield()
self.center()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def textfield(self):
QToolTip.setFont(QFont('SansSerif', 12))
label1 = QLabel("文字自动回复内容:")
self.text1 = QLineEdit()
self.text1.setToolTip("请输入内容")
label2 = QLabel("图片自动回复内容:")
self.text2 = QLineEdit()
self.text2.setToolTip("请输入内容")
grid = QGridLayout()
grid.setSpacing(0)
grid.addWidget(label1, 0, 0)
grid.addWidget(self.text1, 1, 0)
grid.addWidget(label2, 2, 0)
grid.addWidget(self.text2, 3, 0)
btn_login = QPushButton("登录")
grid.addWidget(btn_login, 4, 0, 1, 2)
btn_exit = QPushButton("退出")
grid.addWidget(btn_exit, 5, 0, 1, 2)
btn_login.clicked.connect(self.autoreply)
btn_exit.clicked.connect(self.closeEvent)
self.setLayout(grid)
def autoreply(self):
global text1
global text2
text1 = self.text1.text()
text2 = self.text2.text()
self.t=threading.Thread(target=startReply,args=('1',))
self.t.start()
if __name__ == "__main__":
App = QApplication(sys.argv)
ex = FirstWindow()
ex.show()
sys.exit(App.exec_())
还可以做更多功能,欢迎讨论。
网友评论