Skip to content

Instantly share code, notes, and snippets.

@DataSolveProblems
Last active December 3, 2020 03:51
Show Gist options
  • Save DataSolveProblems/3ef89ec9bbac6cbc36fe59d33a92020a to your computer and use it in GitHub Desktop.
Save DataSolveProblems/3ef89ec9bbac6cbc36fe59d33a92020a to your computer and use it in GitHub Desktop.
import sys
from PyQt5.QtWidgets import QWidget, QProgressBar, QPushButton, QApplication
from PyQt5.QtCore import QBasicTimer
class ProgressBarDemo(QWidget):
def __init__(self):
super().__init__()
self.progressBar = QProgressBar(self)
self.progressBar.setGeometry(30, 40, 200, 25)
self.btnStart = QPushButton('Start', self)
self.btnStart.move(30, 80)
self.btnStart.clicked.connect(self.startProgress)
self.btnReset = QPushButton('Reset', self)
self.btnReset.move(120, 80)
self.btnReset.clicked.connect(self.resetBar)
self.timer = QBasicTimer()
self.step = 0
def resetBar(self):
self.step = 0
self.progressBar.setValue(0)
def startProgress(self):
if self.timer.isActive():
self.timer.stop()
self.btnStart.setText('Start')
else:
self.timer.start(100, self)
self.btnStart.setText('Stop')
def timerEvent(self, event):
if self.step >= 100:
self.timer.stop()
self.btnStart.setText('Start')
return
self.step +=1
self.progressBar.setValue(self.step)
if __name__=='__main__':
app = QApplication(sys.argv)
demo = ProgressBarDemo()
demo.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment