반응형
/*********************************************************************************************************
-- Title : [PyQt4] Progressbar 구현
-- Reference : zetcode.com/gui/pyqt4/widgets/
-- Key word : python pyqt pyqt4 qt qt4 파이썬 프로그레스바 qprogressbar progressbar progress bar
*********************************************************************************************************/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui, QtCore class Window(QtGui.QWidget): def __init__(self): super(Window, self).__init__() self.setGeometry(300, 300, 280, 170) self.setWindowTitle('ProgressBar Test') self.on_init_object() def on_init_object(self): self.tProgressbar = QtGui.QProgressBar(self) self.tProgressbar.setGeometry(30, 40, 200, 25) self.tButton = QtGui.QPushButton('Start', self) self.tButton.move(40, 80) self.tButton.clicked.connect(self.on_button_click) self.tTimer = QtCore.QBasicTimer() self.step = 0 def timerEvent(self, e): # I don't know timerEvent method is system one or not.. if self.step >= 100: self.tTimer.stop() self.tButton.setText('Finished') return self.step += 1 self.tProgressbar.setValue(self.step) def on_button_click(self): if self.tTimer.isActive(): self.tTimer.stop() self.tButton.setText('Start') else: self.tTimer.start(100, self) self.tButton.setText('Stop') if __name__ == "__main__": app = QtGui.QApplication(sys.argv) gui = Window() gui.show() sys.exit(app.exec_()) | cs |
반응형