PyQt4 进度条和日历 代码

# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name:     buttonTest
   Description :
   Author :       神秘藏宝室
   date:          2017-09-30
-------------------------------------------------
   Change Activity:
                   2017-09-30:
-------------------------------------------------
"""
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from PyQt4 import QtGui,QtCore

class ProgressBar(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle(u'进度条')

        self.pbar = QtGui.QProgressBar(self)
        self.pbar.setGeometry(30,40,200,25)

        self.button = QtGui.QPushButton(u'开始',self)
        self.button.setFocusPolicy(QtCore.Qt.NoFocus)
        self.button.move(40,80)

        self.connect(self.button,QtCore.SIGNAL('clicked()'),self.onStart)

        self.timer = QtCore.QBasicTimer()
        self.step = 0

    def onStart(self):
        if self.timer.isActive():
            self.timer.stop()
            self.button.setText(u'开始')
        else:
            self.timer.start(100,self)
            self.button.setText(u'停止')

    def timerEvent(self, *args, **kwargs):
        if self.step >= 100:
            self.timer.stop()
            return
        self.step += 1
        self.pbar.setValue(self.step)


class Calendar(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.setGeometry(300, 300, 350, 300)
        self.setWindowTitle(u'日历')

        self.cal = QtGui.QCalendarWidget(self)
        self.cal.setGridVisible(True)
        self.connect(self.cal,QtCore.SIGNAL('selectionChanged()'),self.showDate)

        self.label = QtGui.QLabel(self)
        date = self.cal.selectedDate()
        self.label.setText(str(date.toPyDate()))

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.cal)
        vbox.addWidget(self.label)
        self.setLayout(vbox)

    def showDate(self):
        date = self.cal.selectedDate()
        self.label.setText(str(date.toPyDate()))





app = QtGui.QApplication(sys.argv)
test = Calendar()
test.show()
sys.exit(app.exec_())

进度条效果

日历效果

posted on 2017-09-30 23:07  神秘藏宝室  阅读(355)  评论(0编辑  收藏  举报

 >>>转载请注明出处<<<