【发布时间】:2017-01-30 18:51:51
【问题描述】:
我已经用 python 玩了大约三个月了,几天前我需要做一些琐碎的任务(创建文件夹),我实际上做了一个脚本来做。
出于纯粹的完美主义,我想添加一个进度条,但是当我运行脚本时,它挂起,然后在完成后说完成。我希望看到进度条达到 100% 而不是挂起。我已经读过我需要使用 python 线程来执行此操作,但我真的很困惑如何实现它但也理解它。
我已经复制了理论上需要线程化的代码部分。如您所见,我正在使用 QT Designer UI 和进度条。
间距也不是问题。这是我第一次在 Stack Overflow 上发帖,如果我在这里弄乱了代码间距,请原谅我。
非常感谢您为我提供的任何启示。
class ShotCreator(QtGui.QDialog):
def __init__(self, *args):
ui = 'ShotCreator_UI.ui'
QtGui.QWidget.__init__(self, *args)
loadUi(ui, self)
self.show()
#Slots
self.connect(self.browseLocation_btn, QtCore.SIGNAL("clicked()"), self.openBrowse)
self.connect(self.create_btn, QtCore.SIGNAL("clicked()"), self.makeDir)
self.progressBar.setValue(0)
def makeDir(self):
#Get data
departments = self.queryValues()
shots = self.fullShotAmount()
proj = self.projName()
#Converting proj to string
proj = str(proj)
#Converting dirLoc to string
dirLoc = self.browseLocation.text()
dirLoc = str(dirLoc)
if dirLoc == "":
msgBox = QtGui.QMessageBox()
msgBox.setIcon(QMessageBox.Warning)
msgBox.setWindowTitle("Oops - Directory Location")
msgBox.setText("Please give a directory location")
msgBox.exec_()
#Creating shot numbers
shot = 0
for s in shots:
shot = shot + 5
sShot = ("00" + str(shot))
if not os.path.exists(sShot):
#Create shot folders
os.mkdir(sShot)
self.progressBar.setValue((int(s) / int(len(shots))* 100))
self.progressBar.setValue(100)
【问题讨论】:
标签: python multithreading for-loop pyqt