from PyQt5.QtWidgets import *
import sys
class WindowDemo(QWidget):
def __init__(self):
super().__init__()
btn1 = QPushButton(self)
btn1.setText('按钮1')
btn2 = QPushButton(self)
btn2.setProperty('name', 'myBtn')
btn2.setText('按钮2')
vbox = QVBoxLayout()
vbox.addWidget(btn1)
vbox.addWidget(btn2)
self.setLayout(vbox)
self.setWindowTitle("QSS样式")
if __name__ == "__main__":
app = QApplication(sys.argv)
win = WindowDemo()
qssStyle = '''
QPushButton[name="myBtn"] {
background-color: red
}
'''
PyQt QSS实例
于 2022-03-17 14:12:28 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)