当前位置:网站首页>PyQt5-颜色对话框(QColorDialog)
PyQt5-颜色对话框(QColorDialog)
2022-07-16 19:05:00 【獜洛橙】
效果如下:

代码如下:
'''
颜色对话框:QColorDialog
'''
'''
字体对话框:QFontDialog
'''
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class QColorDialogDemo(QWidget):
def __init__(self):
super(QColorDialogDemo,self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Color Dialog例子')
layout = QVBoxLayout()
self.colorButton = QPushButton('设置颜色')
self.colorButton.clicked.connect(self.getColor)
layout.addWidget(self.colorButton)
self.colorButton1 = QPushButton('设置背景颜色')
self.colorButton1.clicked.connect(self.getBGColor)
layout.addWidget(self.colorButton1)
self.colorLabel = QLabel('Hello,测试颜色例子')
layout.addWidget(self.colorLabel)
self.setLayout(layout)
def getColor(self):
color = QColorDialog.getColor()
p = QPalette()
p.setColor(QPalette.WindowText,color)
self.colorLabel.setPalette(p)
def getBGColor(self):
color = QColorDialog.getColor()
p = QPalette()
p.setColor(QPalette.Window,color)
self.colorLabel.setAutoFillBackground(True)
self.colorLabel.setPalette(p)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QColorDialogDemo()
main.show()
sys.exit(app.exec_())
边栏推荐
猜你喜欢

Mysql——字符串函数
![Leetcode high frequency question: three unordered arrays a, B, C with length N, find the total number of combinations of (I, J, K) with a[i] + b[j] + c[k] = 64](/img/b0/8ed026a2fab2a3e6c95be2a6a424d9.png)
Leetcode high frequency question: three unordered arrays a, B, C with length N, find the total number of combinations of (I, J, K) with a[i] + b[j] + c[k] = 64

Sword finger offer 53 - ii Missing numbers from 0 to n-1

科技云报道:构建可观测性的核心能力是什么?

Design and sharing of inclinometer based on single chip microcomputer

The University of Leuven recruited postdoctoral researchers to use ai/ml to analyze images of solar activity areas and predict flares

LeetCode+ 86 - 90 双指针、回溯、区间 dp 专题

Layoffs are coming

Classic application method of installing HAP on Hongmeng development board

How to deal with the security risks of the third party in the supply chain
随机推荐
Netstat common scene record
LeetCode+ 86 - 90 双指针、回溯、区间 dp 专题
I'm a little busy recently.
[original] migration of rm500u-cn module driver
词云图,词频图,专门统计某些关键词的词云词频
Simple and efficient code suggestions
将一个文件夹中的内容复制到另一个文件夹中
【图文并茂】U盘启动盘制作 U盘启动盘重装系统教程
Build an enterprise level data governance system from 0 to 1!
Mysql——字符串函数
淺學js中的關系運算符
MySQL notes: the latest tutorial of song Hongkang at site B (under continuous update)
Detailed explanation of the use of documents
Design and sharing of inclinometer based on single chip microcomputer
[cloud native] Devops (IV): integrated sonar Qube
低代码如何助力非标零售业务新增长案例分析
The University of Leuven recruited postdoctoral researchers to use ai/ml to analyze images of solar activity areas and predict flares
Duplicate disk: problems when BN and dropout are used together
图执行引擎那些事(一)
正则表达式