from PyQt5 import QtWidgets
import sys
app = QtWidgets.QApplication(sys.argv)
dialog = QtWidgets.QDialog()
label1 = QtWidgets.QLabel()
label2 = QtWidgets.QLabel()
strT = '<span style=\" color: #ff0000;\">%s</span>' %('helloworld') #红色
label1.setText("%s" %(strT))
strT = '<span style=\" color: #00ff00;\">%s</span>' %('helloworld') #绿色
label2.setText("%s" %(strT ))
label1.show()
label2.show()
sys.exit(app.exec_())
关键: strT = ‘<span style=" color: #00ff00;">%s’ %(‘helloworld’)