-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab10.py
More file actions
59 lines (50 loc) · 1.82 KB
/
Lab10.py
File metadata and controls
59 lines (50 loc) · 1.82 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QLabel, QPushButton,
QLineEdit, QHBoxLayout, QVBoxLayout, QComboBox)
from PyQt5.QtCore import pyqtSlot, QUrl
from PyQt5.QtGui import QColor
colors = {
"Pick a color": ["", ""],
"Peach Puff": [(255, 218, 185), "FFDAB9"],
"Powder Blue": [(176, 224, 230), "B0E0E6"]
}
class NewWindow(QWidget):
def __init__(self):
super().__init__()
class Window(QWidget):
def __init__(self):
super().__init__()
self.my_combo_box = QComboBox()
self.my_combo_box.addItems(colors)
self.rgb = QLabel("RGB: ")
self.hexa = QLabel("Hex: ")
self.showColor = QPushButton('View the color')
vbox = QVBoxLayout()
vbox.addWidget(self.my_combo_box)
vbox.addWidget(self.rgb)
vbox.addWidget(self.hexa)
vbox.addWidget(self.showColor)
self.setLayout(vbox)
self.my_combo_box.currentIndexChanged.connect(self.update_ui)
self.showColor.clicked.connect(self.open_window)
self.setWindowTitle("Colors!")
@pyqtSlot()
def open_window(self):
my_text = self.my_combo_box.currentText()
my_index = self.my_combo_box.currentIndex()
self.new_window = NewWindow()
self.new_window.setAutoFillBackground(True)
backgroundColor = self.new_window.palette()
backgroundColor.setColor(self.new_window.backgroundRole(), QColor(colors[my_text][0][0], colors[my_text][0][1], colors[my_text][0][2]))
self.new_window.setPalette(backgroundColor)
self.new_window.show()
@pyqtSlot()
def update_ui(self):
my_text = self.my_combo_box.currentText()
my_index = self.my_combo_box.currentIndex()
self.rgb.setText(f'RGB: {colors[my_text][0]}')
self.hexa.setText(f'Hex: {colors[my_text][1]}')
app = QApplication(sys.argv)
main = Window()
main.show()
sys.exit(app.exec_())