如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import sys
from pyqt5 import qtgui, qtcore, qtwidgets
from pyqt5.qtwidgets import *
from pyqt5.qtcore import *
from pyqt5.qtgui import *
class showtime(qdialog):
def __init__( self ):
super (showtime, self ).__init__()
self .resize( 500 , 400 )
self .setwindowtitle( "label显示时间" )
self .label = qlabel( self )
self .label.setfixedwidth( 200 )
self .label.move( 90 , 80 )
self .label.setstylesheet( "qlabel{background:white;}"
"qlabel{color:rgb(300,300,300,120);font-size:10px;font-weight:bold;font-family:宋体;}"
)
# 动态显示时间在label上
timer = qtimer( self )
timer.timeout.connect( self .showtime)
timer.start()
def showtime( self ):
datetime = qdatetime.currentdatetime()
text = datetime.tostring()
self .label.settext( " " + text)
if __name__ = = '__main__' :
app = qtwidgets.qapplication(sys.argv)
my = showtime()
my.show()
sys.exit(app.exec_())
|
以上这篇pyqt5 使用label控件实时显示时间的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_32973061/article/details/81095369