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(Example, self).__init__(parnet)

self.setupUi(self)

tim=QtCore.QTimer(self)

tim.timeout.connect(self.times1)

tim.timeout.connect(self.times2)

tim.start(1)

def times1(self):#第一种简单

a=datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M:%S‘)

self.lineEdit.setText(a)

def times2(self):#第二种

a=QtCore.QTime.currentTime()

a1=Qt.QDate.currentDate()

a2=a1.toString(‘yyyy-MM-dd‘)+‘ ‘+a.toString(‘hh:mm:ss‘)

self.lineEdit_2.setText(a2)

def main():

app = QtGui.QApplication(sys.argv)

ex = Example()

ex.show()

sys.exit(app.exec_())

main()

结果如下:

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

时间: 2024-10-23 00:02:54

pyqt 动态显示时间方法例子学习的相关文章

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(E

pyqt使用标准输入框 例子学习,由PyQt4 精彩实例分析提供学习

# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from PyQt4.Qt import * from PyQt4.QtCore import * import sys QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8")) class Example(QDialog): def __init

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 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 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.