# -*- coding: utf- -*-
from PyQt5.QtWidgets import QApplication, QPushButton, QColorDialog , QWidget
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor
import sys
class ColorDialog ( QWidget):
def __init__(self ):
super().__init__()
#颜色值
color = QColor(, , )
#位置
self.setGeometry(, , , )
#标题
self.setWindowTitle('颜色选择')
#按钮名称
self.button = QPushButton('Dialog', self)
self.button.setFocusPolicy(Qt.NoFocus)
#按钮位置
self.button.move(, )
#按钮绑定方法
self.button.clicked.connect(self.showDialog)
self.setFocus()
self.widget = QWidget(self)
self.widget.setStyleSheet('QWidget{background-color:%s} '%color.name())
self.widget.setGeometry(, , , )
def showDialog(self):
col = QColorDialog.getColor()
print(col.name(),"\n")
if col.isValid():
self.widget.setStyleSheet('QWidget {background-color:%s}'%col.name())
if __name__ == "__main__":
app = QApplication(sys.argv)
qb = ColorDialog()
qb.show()
sys.exit(app.exec_())