生活会辜负努力的人,但不会辜负一直努力的人

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

转载:ABigCaiBird

#-*- coding:utf-8 -*-
#######
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import time
import threading
class MyWindow(QDialog,QWidget):
    sigSetTime = pyqtSignal(str)  ####信号定义
    def __init__(self,parent = None):
        super(MyWindow,self).__init__(parent)
        self.setFont(QFont("Roman times",14))#####设置字体
        self.resize(200,50)
        self.mainlayout = QGridLayout(self)
        self.timeLabel = QLabel()
        self.timeLabel.setText(u"时间:")
        self.mainlayout.addWidget(self.timeLabel,0,0,1,1)
        self.timeLineEdit = QLineEdit()
        self.mainlayout.addWidget(self.timeLineEdit,0,1,1,1)
        self.sigSetTime.connect(self.setTime)####信号槽连接
        t = threading.Thread(target = self.getTimeAndSetTime,args=(self.sigSetTime,))
        t.setDaemon(True)
        t.start()

    def setTime(self,str_time):
        self.timeLineEdit.setText(str_time)

    def getTimeAndSetTime(self,setTimeSignal):
        while True:
            setTimeSignal.emit(str(time.localtime().tm_hour)+":"+ str(time.localtime().tm_min) + ":" + str(time.localtime().tm_sec))######信号换发
            time.sleep(1)

app=QApplication(sys.argv)
window=MyWindow()
window.show()
app.exec_()

 

posted on 2018-05-31 16:56  何许亻也  阅读(928)  评论(0)    收藏  举报