氣輕PyQt6 21 時(shí)間編輯器(QTimeEdit)
?
from PyQt6.QtWidgets import *
from PyQt6.QtCore import Qt, QTime
import sys
?
class PyQt621(QWidget):
??? def __init__(self):
??????? super().__init__()
??????? self.initUI()
??? def initUI(self):
??????? self.setWindowTitle('氣輕PyQt6')??????????????? # 設(shè)置窗口標(biāo)題
??????? self.resize(420, 50)??????????????????????????? # 設(shè)置窗口大小
??????? self.setStyleSheet('background-color:#FAEBD7')
?
??????? t = QTime.currentTime().toString('hh:mm:ss')
??????? self.label = QLabel(self)?????????????????????? #設(shè)置label信息
??????? self.label.setGeometry(10, 0,200, 40)?????????? # 設(shè)置位置和大小
??????? self.label.setText(t)
??????? self.label.setAlignment(Qt.AlignmentFlag.AlignHCenter)# 居中設(shè)置
??????? self.label.setStyleSheet('background-color:#00FFFF;color : #696969; \
??????????????????? font: bold italic large /"Times New Roman/";font-size:25px')
?
??????? self.tedit = QTimeEdit(self)
??????? self.tedit.setGeometry(210, 0,200, 40)?????????? # 設(shè)置位置和大小
??????? self.tedit.setDisplayFormat('hh:mm:ss')
??????? self.tedit.setTime(QTime.currentTime())
??????? self.tedit.setStyleSheet('background-color:#87CEFA;color : #00BFFF; \
?????????????? ?????font: bold italic large /"Times New Roman/";font-size:25px')
??????? self.tedit.timeChanged.connect(self.updateLabel)
?
??????? self.show()
?
??? def updateLabel(self,t):
??????? print('t:',t)
??????? print('t.hour():',t.hour(),t.minute(),t.second())
??????? self.label.setText(t.toString('hh:mm:ss'))
?
if __name__ == '__main__':
??? app = QApplication(sys.argv)
??? window = PyQt621()
??? sys.exit(app.exec())
?
執(zhí)行結(jié)果
