Voortgangsbalk
Op deze pagina:
Met een voortgangs balk kun je het verloop laten zien.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class Venster(QtGui.QWidget):
def __init__(self):
super(Venster, self).__init__()
self.initUI()
def initUI(self):
self.pbar = QtGui.QProgressBar(self)
self.pbar.setGeometry(30, 40, 280, 25)
self.btn = QtGui.QPushButton('Start', self)
self.btn.move(40, 80)
self.btn.clicked.connect(self.doAction)
self.timer = QtCore.QBasicTimer()
self.step = 0
self.setGeometry(400, 400, 320, 160)
self.setWindowTitle('Voortgangsbalk')
self.show()
def timerEvent(self, e):
if self.step >= 100:
self.timer.stop()
self.btn.setText('Klaar')
return
self.step = self.step + 1
self.pbar.setValue(self.step)
def doAction(self):
if self.timer.isActive():
self.timer.stop()
self.btn.setText('Start')
else:
self.timer.start(100, self)
self.btn.setText('Stop')
def main():
app = QtGui.QApplication(sys.argv)
ex = Venster()
sys.exit(app.exec_())
if __name__ == '__main__':
main()