设为首页 收藏本站
查看: 1423|回复: 0

[经验分享] python之qt动态时间显示

[复制链接]

尚未签到

发表于 2015-12-2 15:51:11 | 显示全部楼层 |阅读模式
# -*- coding: cp936 -*-
from PyQt4 import QtGui
from PyQt4 import QtCore
import sys,time,random,os,re
from PyQt4.QtGui import *
from PyQt4.QtCore import *
def Class_Import_Image(path):
        i=0#为什么函数名称是这样,因为Image它是一个类的对象,因为要导入所以写成这样
        #while 1:
        try:
             ls=os.listdir(path)
        #except:
             #print('access deny')
        except Exception, e:
                print('access deny')
                print e,ur'文件路径不正确',ur'您的文件路径呢?对不起找错地方了吧',ur'这个地方都能被您找到,真。。。。。'
        else:
            for l in ls:
                print'第',i+1,'次'
                time.sleep(1)
                temp=os.path.join(path,l)
                print ur'创建文件时间:',time.ctime((os.path.getatime(temp))),
                print ur'创建文件夹时间为:', time.ctime(os.path.getctime(os.path.dirname(temp))),
                print len(temp),ur'数量',sum(os.path.getsize(os.path.join(path,l)) for name in temp),ur'字节数',
                if(os.path.isdir(temp)):
                        print(temp)
                        Class_Import_Image(temp)
                else:
                        print(temp)
                i+=1
                if i>4 :
                        #退出
                        sys.exit(0)
def a(path):
    while True:
        image=re.compile('(.jpg$|.gif$)')
        p=image.findall(path)
        if p:
            print p,'您的图片格式找到了,它是以.jpg或.gif的扩展名'
        else:
            print'图片格式错误','你说的是什么格式呀?'
            raise AttributeError
        if sys.argv>=0:
            sys.exit(0)
        else:
            continue
#退出的时间也需要知道下
def Path_time2():
    _time2=time.strftime('%Y年-%m月-%d日 %H:%M:%S',time.localtime(time.time()))
    print '本次退出时间为',_time2
#进入观看图片的时间和退出观看图片的时间
   
class DigiClock(QLCDNumber):
        def __init__(self,parent=None):
                super(DigiClock,self).__init__(parent)
            
                p=self.palette()
                p.setColor(QPalette.Window,Qt.red)
                self.setPalette(p)

                #QtGui.QWidget.__init__(self, parent)
                self.setGeometry(600, 300, 500, 150)
                self.setWindowTitle('Python Pil')
                self.setToolTip(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
                time.sleep(1)
                #self.setToolTip(time.ctime(os.path.getctime(os.path.dirname('e:\\image\\'))))
                self.setWindowIcon(QtGui.QIcon('e:\\image\\abc.jpg'))
                QtGui.QToolTip.setFont(QtGui.QFont('OldEnglish', 10))
               
                self.setNumDigits(19)
                self.dragPosition=None
            
                self.setWindowFlags(Qt.FramelessWindowHint)
                self.setWindowOpacity(0.5)

               
                timer=QTimer(self)
                self.connect(timer,SIGNAL("timeout()"),self.showTime)
                timer.start(1000)
               
                self.showTime()         
                self.resize(400,100)
        def closeEvent(self, event):
                reply = QtGui.QMessageBox.question(self, 'Message',
                "Are you sure to quit?", QtGui.QMessageBox.Yes,
                QtGui.QMessageBox.No)
                if reply == QtGui.QMessageBox.Yes:
                        event.accept()
                else:
                        event.ignore()

               

                self.setWindowTitle('grid layout')
                names = ['Cls', 'Bck', '', 'Close', '7', '8', '9', '/',
                '4', '5', '6', '*', '1', '2', '3',
                '-', '0', '.', '=', '+']
                18
                grid = QtGui.QGridLayout()
                j = 0
                pos = [(0, 0), (0, 1), (0, 2), (0, 3),
                (1, 0), (1, 1), (1, 2), (1, 3),
                (2, 0), (2, 1), (2, 2), (2, 3),
                (3, 0), (3, 1), (3, 2), (3, 3),
                (4, 0), (4, 1), (4, 2), (4, 3)]
                for i in names:
                        button = QtGui.QPushButton(i)
                if j == 2:
                        grid.addWidget(QtGui.QLabel(''), 0, 2)
                else:
                        grid.addWidget(button, pos[j][0], pos[j][1])
                        j = j + 1
                        self.setLayout(grid)
                self.setWindowTitle('signal & slot')
                lcd = QtGui.QLCDNumber(self)
                slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
                vbox = QtGui.QVBoxLayout()
                vbox.addWidget(lcd)
                vbox.addWidget(slider)
                self.setLayout(vbox)
                self.connect(slider, QtCore.SIGNAL('valueChanged(int)'), lcd,
                QtCore.SLOT('display(int)'))
                self.resize(200,10)

        def mousePressEvent(self,event):
                if event.button()==Qt.LeftButton:
                    self.dragPosition=event.globalPos()-self.frameGeometry().topLeft()
                    event.accept()
                if event.button()==Qt.RightButton:
                    self.close()
            
        def mouseMoveEvent(self,event):
                if event.buttons() & Qt.LeftButton:
                    self.move(event.globalPos()-self.dragPosition)
                    event.accept()
            
        def showTime(self):
                time=QTime.currentTime()
                date=QDate.currentDate()
                text= date.toString("yyyy-MM-dd")+" "+time.toString("hh:mm:ss")     
                self.display(text)
                Class_Import_Image('e:\\image\\')
      
def Path_time3():
        try:
                Path_time1()
                time.sleep(random.randint(1,2))
        except Exception:
                app = QtGui.QApplication(sys.argv)
                form=DigiClock()
                form.show()
                app.exec_()
                sys.exit(app.exec_())
                if  a('e:\\image\\*.jp'):
                    sys.exit(0)
                Path_time2()
Path_time3()
如图: DSC0000.png

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-146477-1-1.html 上篇帖子: Python多线程问题的资料查找与汇总by tsy 下篇帖子: [Leetcode][Python]36: Valid Sudoku
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表