现在有一个纯数字的列表,我想让它们各自进行倒计时并且输出在UI界面上
t_list = [26,33,10,18,45,6]
我是这样写的
from PyQt5.QtCore import QThread,pyqtSignal
from PyQt5 import QtCore,QtWidgets
import time
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(553, 588)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(470, 210, 75, 23))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 553, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.List = QtWidgets.QTextBrowser(self.centralwidget)
self.List.setGeometry(20,20,200,300)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton.clicked.connect(lambda :self.tist())
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "开始"))
def tist(self):
self.t_list = [26,33,10,18,45,6]#而且列表的长度也不是固定的
self.starts = qthraed()#倒计时线程
for i in range(len(self.t_list)):
self.starts.myNum = self.t_list[i]
self.starts.start()
self.starts.sinOut.connect(self.List.append)
class qthraed(QThread):
sinOut = pyqtSignal(str)
def __init__(self, parent=None):
super(qthraed, self).__init__(parent)
self.Tist = True
self.num = 0
self.myNum = 1
def __del__(self):
self.Tist = False
self.wait()
def run(self):
while self.myNum>= 0:
self.sinOut.emit(str(self.myNum))
self.myNum -= 1
time.sleep(1)
if __name__ =="__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(w)
w.show()
sys.exit(app.exec_())
输出的结果是用列表的最后一个数字同时进行倒计时
我最终想要的结果是各自进行倒计时并且输出在UI界面上