码迷,mamicode.com
首页 > 其他好文 > 详细

pyqt QTimer,QThread例子学习

时间:2014-08-02 23:10:44      阅读:503      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   os   io   for   2014   art   

# -*- coding: utf-8 -*-

# python:2.x

__author__ = ‘Administrator‘

 

from PyQt4.QtGui import *

from PyQt4.Qt import *

from PyQt4.QtCore import *

from start import Ui_Form

import sys

class Example(QDialog,Ui_Form):

    def __init__(self,parent=None):

        super(Example, self).__init__(parent)

        self.setupUi(self)

 

        #边框风格

        self.timenum.setFrameStyle(QFrame.StyledPanel|

                                         QFrame.Plain)

        self.time=QTimers()

        self.start.clicked.connect(self.start1)

        self.stop.clicked.connect(self.stop1)

        self.connect(self.time, SIGNAL("updateTime()")

                        , self.updateTime)

        self.setWindowFlags(Qt.WindowMinimizeButtonHint)#禁止改变窗口的大小

    def updateTime(self):

        self.timenum.setText(u‘时间为{0}‘.format(QString.number(self.num)))

        self.num+=1

    def stop1(self):

        self.time.stop1()

        self.stop.setEnabled(False)

        self.start.setEnabled(True)

        self.timenum.setText(u‘请输入时间0‘)

    def start1(self):

        self.num=0

        self.start.setEnabled(False)

        self.stop.setEnabled(True)

        self.time.start()

from time import *

class QTimers(QThread):

    def __init__(self, parent=None):

        super(QTimers,self).__init__(parent)

        self.stoped=False

        self.mutex=QMutex()#提供的是线程之间的访问顺序化

    def run(self):

        with QMutexLocker(self.mutex):#QMutexLocker ( QMutex * mutex )

            self.stoped=False

        while True:

            if self.stoped:

                return

            self.emit(SIGNAL(‘updateTime()‘))#发送信号

            sleep(1)

    def stop1(self):

        with QMutexLocker(self.mutex):

            self.stoped=True

    def isStoped(self):

        with QMutexLocker(self.mutex):

            return self.stoped

 

 

 

app =QApplication(sys.argv)

QApplication.setQuitOnLastWindowClosed(False)

x = Example()

x.show()

sys.exit(app.exec_())

 如图:bubuko.com,布布扣

pyqt QTimer,QThread例子学习,布布扣,bubuko.com

pyqt QTimer,QThread例子学习

标签:style   blog   http   os   io   for   2014   art   

原文地址:http://www.cnblogs.com/mhxy13867806343/p/3887505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!