pyqt5中已经使用uic.loadUi()动态加载UI文件,如何实现按钮和多进程绑定成功
目前运行会报错 TypeError: Pool.map() missing 1 required positional argument: 'iterable'
我想要达到的结果:用动态UI加载方式,点击按钮实现同一个函数同步运行多次!
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QThread, pyqtSignal
from threading import Thread
import time
from multiprocessing import Process,Pool
# 继承QThread
class Mythread(QThread):
breakSignal = pyqtSignal(int) # 传输整数型
# 实例化
so = Mythread()
# 加载UI文件
class Stats():
def __init__(self):
self.ui = uic.loadUi('Click_Ui.ui')
# 自定义信号的处理函数
so.breakSignal.connect(self.printToGui)
self.jdt()
def jdt(self):
# 进度条默认设置
self.pv = 0
self.ui.progressBar.setRange(0, 100)
self.ui.progressBar.setValue(self.pv)
# 按钮默认设置
self.ui.startButton.setText('开始')
# self.ui.startButton.clicked.connect(self.myTimerState)
def myTimerState(self):
if self.ui.startButton.text() == '开始':
self.ui.progressBar.setValue(0)
self.ui.startButton.setText('停止')
# 启动脚本
self.jb()
else:
self.ui.startButton.setText('开始')
def jb(self):
def run():
for i in range(100):
# self.ui.progressBar.setValue(round(int(i/100*100),0))
so.breakSignal.emit(round(int(i/100*100), 0))
i += 1
print(i)
time.sleep(1)
Thread(target=run).start()
# 槽函数
def printToGui(self, pv):
self.ui.progressBar.setValue(pv)
def main_tracker():
p = Pool(4)
p.map(stats.myTimerState)
p.close()
p.join()
# 开始程序
if __name__ == '__main__':
App = QApplication(sys.argv)
stats = Stats()
stats.ui.show()
stats.ui.startButton.clicked.connect(main_tracker)
sys.exit(App.exec_())