码迷,mamicode.com
首页 > 其他好文 > 详细

进度条

时间:2015-01-04 18:37:58      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

import sys

from PyQt4 import QtGui, QtCore

class Example(QtGui.QWidget):

    def __init__(self):

        super(Example, self).__init__()

        self.initUI()

    def initUI(self):

        self.pbar = QtGui.QProgressBar(self)

        self.pbar.setGeometry(30, 40, 200, 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(300, 300, 280, 170)

        self.setWindowTitle(‘QtGui.QProgressBar‘)

        self.show()

    def timerEvent(self, e):

        if self.step >= 100:

            self.timer.stop()

            self.btn.setText(‘Finished‘)

            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 = Example()

    sys.exit(app.exec_())

if __name__ == ‘__main__‘:

    main()

 技术分享

进度条

标签:

原文地址:http://www.cnblogs.com/mhxy13867806343/p/4201474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!