一、思维导图
二、代码
import sysfrom PyQt6.QtTextToSpeech import QTextToSpeech
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QLineEdit
from PyQt6 import uic
from PyQt6.QtCore import Qt, QTimerEvent, QTimeclass MyWidget(QWidget):def __init__(self):super().__init__()ui = uic.loadUi("./Form.ui",self)self.label:QLabel = ui.labelself.pushButton:QPushButton = ui.pushButtonself.lineEdit:QLineEdit = ui.lineEditself.lineEdit_2:QLineEdit = ui.lineEdit_2self.pushButton.clicked.connect(self.Btn_slot)self.id = self.startTimer(1000)self.Signal = 0self.speecher = QTextToSpeech()def timerEvent(self, a0:QTimerEvent):if a0.timerId() == self.id:sys_time = QTime.currentTime()t = sys_time.toString('hh:mm:ss')self.label.setText(t)self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)if self.label.text() == self.lineEdit.text() and self.Signal == 1:self.speecher.say(self.lineEdit_2.text() * 5)self.Signal = 0def Btn_slot(self):self.Signal = 1if __name__ == '__main__':app = QApplication(sys.argv)myWidget = MyWidget()myWidget.show()sys.exit(app.exec())
三、结果