from PySide6.QtGui import QTextCharFormat, QColor
from PySide6.QtCore import Qt
def print_with_color(self, variable1, text1, variable2, text2, variable3, Text3, variable4, Text4, color1, color2, color3, color4, color5, color6, color7, color8):
cursor = self.plainTextEdit.textCursor()
format1 = QTextCharFormat()
format1.setForeground(color1)
format2 = QTextCharFormat()
format2.setForeground(color2)
format3 = QTextCharFormat()
format3.setForeground(color3)
format4 = QTextCharFormat()
format4.setForeground(color4)
format5 = QTextCharFormat()
format5.setForeground(color5)
format6 = QTextCharFormat()
format6.setForeground(color6)
format7 = QTextCharFormat()
format7.setForeground(color7)
format8 = QTextCharFormat()
format8.setForeground(color8)
cursor.insertText(variable1, format1)
cursor.insertText(text1, format1)
cursor.insertText(variable2, format2)
cursor.insertText(text2, format2)
cursor.insertText(variable3, format3)
cursor.insertText(Text3, format3)
cursor.insertText(variable4, format4)
cursor.insertText(Text4, format4)
# 可以根据需要继续插入其他变量和文本
self.print_with_color("variable1", " Text1 ", "variable2", " text2", "variable3", "Text3", "variable4", "Text4", Qt.red, Qt.blue, Qt.green, Qt.black, Qt.yellow, Qt.magenta, Qt.cyan, Qt.darkGray)