-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor_dialog.py
44 lines (33 loc) · 1.03 KB
/
color_dialog.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
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QColorDialog
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QColor
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'PyQt5 color dialog - pythonspot.com'
self.left = 10
self.top = 10
self.width = 320
self.height = 200
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
button = QPushButton('Open color dialog', self)
button.setToolTip('Opens color dialog')
button.move(10, 10)
button.clicked.connect(self.on_click)
self.show()
@pyqtSlot()
def on_click(self):
openColorDialog(self)
def openColorDialog(self):
color = QColorDialog.getColor()
if color.isValid():
print(color.name())
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())