1 # -*- coding:utf-8 -*- 2 ''' 3 Created on Sep 17, 2018 4 5 @author: SaShuangYiBing 6 7 Comment: 8 ''' 9 import sys 10 from PyQt5.QtGui import QColor 11 from PyQt5.QtWidgets import QApplication,QWidget,QColorDialog,QPushButton,QFrame 12 13 class New_test(QWidget): 14 def __init__(self): 15 super().__init__() 16 self.initUI() 17 18 def initUI(self): 19 col = QColor(0,0,0) 20 21 btn = QPushButton('Diaglog',self) 22 btn.move(20,20) 23 btn.clicked.connect(self.showdiaglog) 24 25 self.frm = QFrame(self) 26 self.frm.setStyleSheet('QWidget {background-color:%s}' %col.name()) 27 self.frm.setGeometry(130,22,100,100) 28 self.setGeometry(300,300,250,180) 29 self.setWindowTitle('Color Diaglog') 30 self.show() 31 32 def showdiaglog(self): 33 col = QColorDialog.getColor() 34 35 if col.isValid(): 36 self.frm.setStyleSheet('QWidget {background-color:%s}' %col.name()) 37 38 if __name__ == '__main__': 39 app = QApplication(sys.argv) 40 ex = New_test() 41 sys.exit(app.exec_()) 42