|
@@ -0,0 +1,61 @@
|
|
1
|
+import sys
|
|
2
|
+from PyQt5.QtWidgets import *
|
|
3
|
+from PyQt5.QtCore import *
|
|
4
|
+from PyQt5.QtGui import *
|
|
5
|
+
|
|
6
|
+class MyWindow(QMainWindow):
|
|
7
|
+ def __init__(self):
|
|
8
|
+ super().__init__()
|
|
9
|
+ self.title = 'SWH Academy Window.'
|
|
10
|
+ self.left = 200
|
|
11
|
+ self.top = 100
|
|
12
|
+ self.width = 600
|
|
13
|
+ self.height = 550
|
|
14
|
+ self.initUI()
|
|
15
|
+
|
|
16
|
+ def initUI(self):
|
|
17
|
+ self.setWindowTitle(self.title)
|
|
18
|
+ self.setGeometry(self.left, self.top, self.width, self.height)
|
|
19
|
+
|
|
20
|
+ self.label = QLabel("", self)
|
|
21
|
+ self.label.move(10, 20)
|
|
22
|
+ self.label.resize(580, 460)
|
|
23
|
+
|
|
24
|
+ self.catImg1 = QPixmap("cat1.jpeg")
|
|
25
|
+ self.catImg2 = QPixmap("cat2.jpg")
|
|
26
|
+ self.catImg3 = QPixmap("cat3.jpg")
|
|
27
|
+
|
|
28
|
+ self.comboBox = QComboBox(self)
|
|
29
|
+ self.comboBox.addItem('코야') # 단일 아이템 추가시
|
|
30
|
+ self.comboBox.addItems(["레종", "유키"]) # 다수 아이템 추가시
|
|
31
|
+ self.comboBox.insertSeparator(2) # 구분 선
|
|
32
|
+ self.comboBox.setCurrentIndex(0) # 최초 선택된 인덱스
|
|
33
|
+ self.comboBox.move(130, 500)
|
|
34
|
+ self.comboBox.currentTextChanged.connect(self.comboBoxChanged) # 현재 인덱스의 데이터가 바뀔 때
|
|
35
|
+
|
|
36
|
+# self.comboBoxChanged()
|
|
37
|
+
|
|
38
|
+# def comboBoxChanged(self):
|
|
39
|
+# if self.comboBox.currentText() == '코야':
|
|
40
|
+# self.label.setPixmap(self.catImg1)
|
|
41
|
+# elif self.comboBox.currentText() == '레종':
|
|
42
|
+# self.label.setPixmap(self.catImg2)
|
|
43
|
+# else:
|
|
44
|
+# self.label.setPixmap(self.catImg3)
|
|
45
|
+
|
|
46
|
+ self.comboBoxChanged('코야')
|
|
47
|
+
|
|
48
|
+ def comboBoxChanged(self, text):
|
|
49
|
+ if text == '코야':
|
|
50
|
+ self.label.setPixmap(self.catImg1)
|
|
51
|
+ elif text == '레종':
|
|
52
|
+ self.label.setPixmap(self.catImg2)
|
|
53
|
+ else:
|
|
54
|
+ self.label.setPixmap(self.catImg3)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+if __name__ == "__main__":
|
|
58
|
+ app = QApplication(sys.argv)
|
|
59
|
+ mywindow = MyWindow()
|
|
60
|
+ mywindow.show()
|
|
61
|
+ app.exec_()
|