HSL颜色体系知识见https://blog.csdn.net/xulibo5828/article/details/160521898执行脚本# -*- coding: utf-8 -*- # 色相字典 h_dict { 灰色: 0, 红色: 0, 棕色: 20, 橙色: 30, 橙黄: 45, 黄色: 60, 黄绿: 90, 绿色: 120, 青绿: 150, 青色: 180, 靛蓝: 210, 蓝色: 240, 紫色: 270, 品红: 300, 紫红: 330, } color_str # -*- coding: utf-8 -*-\n黑色 \hsl(0, 0%, 0%)\\n白色 \hsl(0, 0%, 100%)\\n color_names h_dict.keys() for color_name, h in h_dict.items(): if color_name 灰色: f 5 t 10 else: t 105 for s in range(5, t, 5): for l in range(5, 100, 5): if color_name 灰色: color_str .join([color_str, f{color_name}_{l}, f \hsl({h}, 0%, {l}%)\, \n]) else: color_str .join([color_str, f{color_name}{s}_{l}, f \hsl({h}, {s}%, {l}%)\, \n]) with open(colors.py, w, encodingutf-8) as f: f.write(color_str) print(颜色文件生成成功)将会得到一个文件colors.py文件中每个颜色的色彩浓度和亮度每间隔5%创建了一个颜色名黑白灰色的H色相和S色彩浓度恒为0黑白灰颜色名的数字是HSL颜色的L亮度。其余颜色的数字是S色彩浓度5%-100%和L亮度5%-95%比如红色5_30 hsl(h0, s5%, l30%)。使用demofrom PySide6.QtWidgets import QApplication, QLabel, QWidget, QGridLayout from colors import * # 导入颜色 app QApplication([]) back_clor fqradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.3, fy:0.3, stop:0 {绿色95_80}, stop:0.2 {绿色95_50}, stop:1 {绿色95_20}) widget QWidget() label QLabel() label.setFixedSize(200,200) label.setStyleSheet(f background-color:{back_clor}; border-radius: 100px; ) layout QGridLayout() layout.addWidget(label) widget.setLayout(layout) widget.show() app.exec()from PySide6.QtGui import QFont from PySide6.QtWidgets import QApplication, QWidget, QGridLayout, QPushButton from UI.colors import * # 导入颜色 app QApplication([]) style_sheet \ fQPushButton {{background-color: qlineargradient(x1: 1, y1: 0, x2: 1, y2: 1, stop: 0 {黄色85_85}, stop: 0.15 {黄色85_85}, stop: 0.3 {黄色80_60}, stop: 1.0 {橙黄90_30}); border-top: 3px solid {橙黄85_40}; border-left: 3px solid {橙黄85_40}; border-right: 3px solid {橙黄85_40}; border-bottom: 3px solid {橙黄85_40}; border-radius: 30px; }} widget QWidget() btn QPushButton(PushButton) btn.setFixedSize(400, 100) btn.setStyleSheet(style_sheet) font QFont() font.setPointSize(26) btn.setFont(font) layout QGridLayout() layout.addWidget(btn) widget.setLayout(layout) widget.show() app.exec()