• 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_())
    
    

    进度条效果

    日历效果

  • 相关阅读:
    ubuntu server 12.04中文显示不了
    hustoj升级
    oj资源
    考试系统
    怎样用DOS命令替换文本里的某段字符
    ubuntu一键安装lamp
    Windows Server 2008官方简体中文正式版下载+序列号
    vsphere ubuntu网速很慢
    前端
    (运维)VMwarevCenterServerAppliance5.0安装与部署
  • 原文地址:https://www.cnblogs.com/Mysterious/p/7616443.html
Copyright © 2020-2023  润新知