pyqt4 利用信号槽在子线程里面操作Qt界面

来源:互联网 发布:中文网络搜索引擎名称 编辑:程序博客网 时间:2024/06/05 01:11
#-*- coding:utf-8 -*-#######from PyQt4.QtCore import *from PyQt4.QtGui import *import sysimport timeimport threadingclass 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_()
0 0
原创粉丝点击