-
Notifications
You must be signed in to change notification settings - Fork 76
/
TestCColorPicker.py
47 lines (36 loc) · 1.2 KB
/
TestCColorPicker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年4月25日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: [email protected]
@file: TestCColorPicker
@description:
"""
__Author__ = 'Irony'
__Copyright__ = 'Copyright (c) 2019'
import cgitb
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QLabel, QDialog, QWidget, QVBoxLayout,\
QPushButton
from CustomWidgets.CColorPicker.CColorPicker import CColorPicker
sys.excepthook = cgitb.enable(1, None, 5, '')
app = QApplication(sys.argv)
def getColor():
ret, color = CColorPicker.getColor()
if ret == QDialog.Accepted:
r, g, b, a = color.red(), color.green(), color.blue(), color.alpha()
label.setText('color: rgba(%d, %d, %d, %d)' % (r, g, b, a))
label.setStyleSheet(
'background: rgba(%d, %d, %d, %d);' % (r, g, b, a))
window = QWidget()
window.resize(200, 200)
layout = QVBoxLayout(window)
label = QLabel('', window, alignment=Qt.AlignCenter)
button = QPushButton('点击选择颜色', window, clicked=getColor)
layout.addWidget(label)
layout.addWidget(button)
window.show()
sys.exit(app.exec_())