|
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QTableWidgetItem
from ui_form import Ui_MainWindow
from PyQt5 import QtWidgets, QtGui, QtCore
from bs4 import BeautifulSoup
import requests
import ctypes
# 继承QThread
class Runthread(QtCore.QThread):
# python3,pyqt5与之前的版本有些不一样
# 通过类成员对象定义信号对象
_signal = QtCore.pyqtSignal(str)
def __init__(self, parent=None):
super(Runthread, self).__init__()
def __del__(self):
self.wait()
def run(self):
print("run 666")
self._signal.emit("run 666") # 信号发送
# 处理你要做的业务逻辑,这里是通过一个回调来处理数据,这里的逻辑处理写自己的方法
# wechat.start_auto(self.callback)
# self._signal.emit(msg); 可以在这里写信号焕发
def callback(self, msg):
pass
# 信号焕发,我是通过我封装类的回调来发起的
# self._signal.emit(msg);
class mwindow(QMainWindow,Ui_MainWindow):
def __init__(self):
super(mwindow, self).__init__()
self.setupUi(self)
self.tableWidget.setColumnWidth(1, 430)
#点击采集事件
self.pushButton.clicked.connect(self.start)
self.pushButton_3.clicked.connect(self.send_thread)
self.pushButton_4.clicked.connect(self.stop) #发送暂停
self.pushButton_5.clicked.connect(self.get_jiaodian)
self.tableWidget.clicked.connect(self.table_clicked)
def stop(self):
# 创建线程
self.thread = Runthread()
# 连接信号
self.thread._signal.connect(self.send)
self.thread.__del__()
def get_jiaodian(self):
dll = ctypes.windll.LoadLibrary("send.dll")
jiaodian = ctypes.string_at(dll.get_window()).decode("utf-8")
self.lineEdit_2.setText(jiaodian)
def send_thread(self):
# 创建线程
self.thread = Runthread()
# 连接信号
self.thread._signal.connect(self.send)
# 开始线程
self.thread.start()
def send(self):
rowCount = self.tableWidget.rowCount()
dll = ctypes.windll.LoadLibrary("send.dll")
jiaodian = self.lineEdit_2.text()
for item in range(rowCount):
address = self.tableWidget.item(item, 2).text()
dll.send_info(bytes(address.encode("utf8")), bytes(jiaodian.encode("utf8")))上一篇用易语言写的,这一次用python和pyqt5写的,学习交流
|
|