本文主要是介绍PyQt6 ------ 如何在 QTextEditor 组件中按顺序递增显示提示信息,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
PyQt6 ------ 如何在 QTextEditor 组件中按顺序递增显示提示信息
- 推荐阅读
- 正文
推荐阅读
PyQt6 ------ 如何在 QLineEditor 组件中按顺序显示提示信息
正文
在推荐阅读中我们已经介绍过背景了,这里直接上代码:
from PyQt6.QtCore import Qt, pyqtSlot, QTimer
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QTextEdit, QVBoxLayout, QWidget
from gui_file import YourCalculatorclass YourGUI(QMainWindow):def __init__(self):super().__init__()self.setFixedSize(800, 600)self.calculator = YourCalculator()self.calculator.task_completed.connect(self.on_task_completed)button = QPushButton("Start Tasks")button.clicked.connect(self.start_tasks)button.setFixedSize(200, 20)self.text_editor = QTextEdit("hhh")self.text_editor.setFixedSize(200, 200)widget = QWidget(self)widget.setFixedSize(400, 600)layout = QVBoxLayout(widget)layout.addWidget(button)layout.addWidget(self.text_editor)self.timer = Noneself.task_index = Nonedef start_tasks(self):self.task_index = 1self.timer = QTimer()self.timer.timeout.connect(self.execute_tasks)self.timer.start(500)def execute_tasks(self):if self.task_index <= 3:task_method = getattr(self.calculator, f"task{self.task_index}")task_method()self.task_index += 1else:self.timer.stop()@pyqtSlot(str)def on_task_completed(self, message):current_text = self.text_editor.toPlainText()new_text = current_text + '\n' + messageself.text_editor.setText(new_text)if __name__ == "__main__":app = QApplication([])window = YourGUI()window.show()app.exec()
如果大家觉得有用,就请点个赞吧~
这篇关于PyQt6 ------ 如何在 QTextEditor 组件中按顺序递增显示提示信息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!