我有一个进度条,我想轻松更新进度。我想象这样的事情。一个脚本是通用的,描述了进度条。另一个将更新它。
from progress_bar import Ui_Dialog
import sys
from PyQt5 import QtCore, QtWidgets
import time
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
ui.set_min_max(0,200)
for i in range(1, 201):
ui.setProgress(i)
time.sleep(0.1)
sys.exit(app.exec_())
进度条说明:
from PyQt5 import QtCore, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 133)
self.progressBar = QtWidgets.QProgressBar(Dialog)
self.progressBar.setGeometry(QtCore.QRect(20, 10, 361, 23))
self.progressBar.setProperty("value", 24)
self.progressBar.setObjectName("progressBar")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(20, 40, 361, 61))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.progressBar.minimum = 1
self.progressBar.maximum = 100
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "PushButton"))
self.progressBar.setValue(0)
def setProgress(self, value):
self.progressBar.setValue(value)
def set_min_max(self,mini,maxi):
self.progressBar.minimum = mini
self.progressBar.maximum = maxi
有没有办法将进度条启动到另一个线程并从原始脚本更新它?