当前位置: 首页 > 行业动态 > 正文

气轻PyQt5 21 时间编辑器(QTimeEdit)

来源 : 哔哩哔哩    时间:2023-04-14 07:15:10

from PyQt5.QtWidgets import *


(资料图片仅供参考)

from PyQt5.QtCore import Qt, QTime

import sys

class PyQt521(QWidget):

def __init__(self):

super().__init__()

self.initUI()

def initUI(self):

self.setWindowTitle('气轻PyQt5')                # 设置窗口标题

self.resize(420, 50)                            # 设置窗口大小

self.setStyleSheet('background-color:#FAEBD7')

t = QTime.currentTime().toString('hh:mm:ss')

self.label = QLabel(self)                       #设置label信息

self.label.setGeometry(10, 0,200, 40)           # 设置位置和大小

self.label.setText(t)

self.label.setAlignment(Qt.AlignHCenter)# 居中设置

self.label.setStyleSheet('background-color:#FFB90F;color : #458B00; \

font: bold italic large /"Times New Roman/";font-size:25px')

self.tedit = QTimeEdit(self)

self.tedit.setGeometry(210, 0,200, 40)           # 设置位置和大小

self.tedit.setDisplayFormat('hh:mm:ss')

self.tedit.setTime(QTime.currentTime())

self.tedit.setStyleSheet('background-color:#8FBC8F;color : #FFF68F; \

font: bold italic large /"Times New Roman/";font-size:25px')

self.tedit.timeChanged.connect(self.updateLabel)

self.show()

def updateLabel(self,t):

self.label.setText(t.toString('hh:mm:ss'))

if __name__ == '__main__':

app = QApplication(sys.argv)

window = PyQt521()

sys.exit(app.exec())

执行结果

X 关闭

精心推荐

Copyright ©  2015-2022 亚洲建筑网版权所有  备案号:豫ICP备20022870号-9   联系邮箱:553 138 779@qq.com