pyqt QTimer,QThread例子学习

# -*- 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_())

如图:

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

时间: 2024-10-12 19:51:06

pyqt QTimer,QThread例子学习的相关文章

pyqt 按钮调用例子学习

UI文件及代码文件:http://yunpan.cn/QCktWsjsgRakf(提取码:d330) 如下图: .PY文件代码如下: from a import Ui_Form from b import Ui_Form1 import sys from PyQt4.QtGui import  * from PyQt4.QtCore import * from PyQt4.Qt import * class Exr02(QDialog,Ui_Form): def __init__(self,pa

pyqt 动态显示时间方法例子学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' import sys,datetime from PyQt4.QtCore import Qt from PyQt4 import QtGui,QtCore,Qt from ti import Ui_Form class Example(QtGui.QDialog,Ui_Form): def __init__(self,parnet=None): super(Exa

pyqt QTableWidget例子学习(重点)

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from PyQt4.Qt import * from PyQt4.QtCore import * lista = ['aa', 'ab', 'ac'] listb = ['ba', 'bb', 'bc'] listc = ['ca', 'cb', 'cc'] mystruct = {'A':lista, 'B':

pyqt 正则表达式例子学习

def rex01(self): username=QtCore.QRegExp('[a-zA-Z0-9_]{2,10}') self.names.setValidator(QtGui.QRegExpValidator(username,self)) mainname=QtCore.QRegExp("^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$") self.mains.setValidator(QtGui.QRegExpValidator(mainnam

pyqt单选,复选等例子学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from PyQt4.Qt import * from PyQt4.QtCore import * from check1 import Ui_Dialog from check2 import Ui_Dialog1 from check3 import Ui_Dialog2 import sys QTextCod

pyqt columnView例子学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import  * from PyQt4.Qt import * from PyQt4.QtCore import * import sys class Tree(QColumnView): def __init__(self,parnet=None,*args): super(Tree,self).__init__(parnet,

pyqt 托盘例子学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from PyQt4.Qt import * from PyQt4.QtCore import * from tp import Ui_Form import sys from PyQt4.QtCore import Qt QTextCodec.setCodecForTr(QTextCodec.codecForNa

pyqt tabWidget例子学习1

from PyQt4 import QtGui from PyQt4 import QtCore from PyQt4.QtCore import pyqtSlot,SIGNAL,SLOT import sys class myTabWidget(QtGui.QTabWidget): def tabChangedSlot(self,argTabIndex): QtGui.QMessageBox.information(self,"Tab Index Changed!", "C

pyqt QTreeWidget例子学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import  * from PyQt4.Qt import * from PyQt4.QtCore import * import sys class Tree(QMainWindow): def __init__(self,parnet=None): super(Tree,self).__init__(parnet) self.