tobby48 6 years ago
parent
commit
f2cd0b8821

+ 47
- 52
src/kr/co/swh/lecture/python/pyqt5/checkbox.py View File

@@ -1,53 +1,48 @@
1
-import sys
2
-from PyQt5.QtWidgets import *
3
-from PyQt5.QtCore import *
4
-
5
-class MyWindow(QMainWindow):
6
-    def __init__(self):
7
-        super().__init__()
8
-        self.title = 'SWH Academy Window.'
9
-        self.left = 200
10
-        self.top = 200
11
-        self.width = 360
12
-        self.height = 150
13
-        self.initUI()
14
-
15
-    def initUI(self):
16
-        self.setWindowTitle(self.title)
17
-        self.setGeometry(self.left, self.top, self.width, self.height)
18
-
19
-        self.label = QLabel("", self)
20
-        self.label.move(50, 20)
21
-        self.label.resize(220, 60)
22
-        
23
-        self.checkBox1 = QCheckBox("SWH Academy ", self)
24
-        self.checkBox1.move(20, 90)
25
-        self.checkBox1.setChecked(True)
26
-        self.checkBox1.stateChanged.connect(self.checkBoxState)
27
-        
28
-        self.checkBox2 = QCheckBox("Coding ", self)
29
-        self.checkBox2.move(140, 90)
30
-        self.checkBox2.stateChanged.connect(self.checkBoxState)
31
-        
32
-        self.checkBox3 = QCheckBox("WorldHistory ", self)
33
-        self.checkBox3.move(220, 90)
34
-        self.checkBox3.stateChanged.connect(self.checkBoxState)
35
-        
36
-        self.checkBoxState()
37
-        
38
-    def checkBoxState(self):
39
-        message = ""
40
-        if self.checkBox1.isChecked():
41
-            message += self.checkBox1.text();
42
-        if self.checkBox2.isChecked():
43
-            message += self.checkBox2.text();
44
-        if self.checkBox3.isChecked():
45
-            message += self.checkBox3.text();
46
-            
47
-        self.label.setText(message)
48
-        
49
-if __name__ == "__main__":
50
-    app = QApplication(sys.argv)
51
-    mywindow = MyWindow()
52
-    mywindow.show()
1
+import sys
2
+from PyQt5.QtWidgets import *
3
+from PyQt5.QtCore import *
4
+
5
+class MyWindow(QMainWindow):
6
+    def __init__(self):
7
+        super().__init__()
8
+        self.initUI()
9
+
10
+    def initUI(self):
11
+        self.setWindowTitle('SWH Academy Window.')
12
+        self.setGeometry(200, 200, 360, 150)
13
+
14
+        self.label = QLabel("", self)
15
+        self.label.move(50, 20)
16
+        self.label.resize(220, 60)
17
+        
18
+        self.checkBox1 = QCheckBox("SWH Academy ", self)
19
+        self.checkBox1.move(20, 90)
20
+        self.checkBox1.setChecked(True)
21
+        self.checkBox1.stateChanged.connect(self.checkBoxState)
22
+        
23
+        self.checkBox2 = QCheckBox("Coding ", self)
24
+        self.checkBox2.move(140, 90)
25
+        self.checkBox2.stateChanged.connect(self.checkBoxState)
26
+        
27
+        self.checkBox3 = QCheckBox("WorldHistory ", self)
28
+        self.checkBox3.move(220, 90)
29
+        self.checkBox3.stateChanged.connect(self.checkBoxState)
30
+        
31
+        self.checkBoxState()
32
+        
33
+    def checkBoxState(self):
34
+        message = ""
35
+        if self.checkBox1.isChecked():
36
+            message += self.checkBox1.text();
37
+        if self.checkBox2.isChecked():
38
+            message += self.checkBox2.text();
39
+        if self.checkBox3.isChecked():
40
+            message += self.checkBox3.text();
41
+            
42
+        self.label.setText(message)
43
+        
44
+if __name__ == "__main__":
45
+    app = QApplication(sys.argv)
46
+    mywindow = MyWindow()
47
+    mywindow.show()
53 48
     app.exec_()

+ 55
- 60
src/kr/co/swh/lecture/python/pyqt5/combobox.py View File

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

+ 39
- 44
src/kr/co/swh/lecture/python/pyqt5/label.py View File

@@ -1,45 +1,40 @@
1
-import sys
2
-from PyQt5.QtWidgets import *
3
-from PyQt5.QtCore import *
4
-
5
-class MyWindow(QMainWindow):
6
-    def __init__(self):
7
-        super().__init__()
8
-        self.title = 'SWH Academy Window.'
9
-        self.left = 200
10
-        self.top = 200
11
-        self.width = 360
12
-        self.height = 100
13
-        self.initUI()
14
-
15
-    def initUI(self):
16
-        self.setWindowTitle(self.title)
17
-        self.setGeometry(self.left, self.top, self.width, self.height)
18
-
19
-        self.label = QLabel("", self)
20
-        self.label.move(120, 20)
21
-        self.label.resize(150, 30)
22
-
23
-        button1 = QPushButton("클릭", self)
24
-        button1.move(20, 50)
25
-        button1.clicked.connect(self.button1Clicked)
26
-
27
-        button2 = QPushButton("지우기", self)
28
-        button2.move(130, 50)
29
-        button2.clicked.connect(self.button2Clicked)
30
-        
31
-        button3 = QPushButton("종료", self)
32
-        button3.move(240, 50)
33
-        button3.clicked.connect(QCoreApplication.instance().quit)
34
-
35
-    def button1Clicked(self):
36
-        self.label.setText("버튼이 클릭되었습니다.")
37
-
38
-    def button2Clicked(self):
39
-        self.label.clear()
40
-        
41
-if __name__ == "__main__":
42
-    app = QApplication(sys.argv)
43
-    mywindow = MyWindow()
44
-    mywindow.show()
1
+import sys
2
+from PyQt5.QtWidgets import *
3
+from PyQt5.QtCore import *
4
+
5
+class MyWindow(QMainWindow):
6
+    def __init__(self):
7
+        super().__init__()
8
+        self.initUI()
9
+
10
+    def initUI(self):
11
+        self.setWindowTitle('SWH Academy Window.')
12
+        self.setGeometry(200, 200, 360, 100)
13
+
14
+        self.label = QLabel("", self)
15
+        self.label.move(120, 20)
16
+        self.label.resize(150, 30)
17
+
18
+        button1 = QPushButton("클릭", self)
19
+        button1.move(20, 50)
20
+        button1.clicked.connect(self.button1Clicked)
21
+
22
+        button2 = QPushButton("지우기", self)
23
+        button2.move(130, 50)
24
+        button2.clicked.connect(self.button2Clicked)
25
+        
26
+        button3 = QPushButton("종료", self)
27
+        button3.move(240, 50)
28
+        button3.clicked.connect(QCoreApplication.instance().quit)
29
+
30
+    def button1Clicked(self):
31
+        self.label.setText("버튼이 클릭되었습니다.")
32
+
33
+    def button2Clicked(self):
34
+        self.label.clear()
35
+        
36
+if __name__ == "__main__":
37
+    app = QApplication(sys.argv)
38
+    mywindow = MyWindow()
39
+    mywindow.show()
45 40
     app.exec_()

+ 42
- 47
src/kr/co/swh/lecture/python/pyqt5/label2.py View File

@@ -1,48 +1,43 @@
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 = 200
12
-        self.width = 360
13
-        self.height = 150
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(90, 20)
22
-        self.label.resize(172, 60)
23
-        self.img = QPixmap("poster.png")
24
-        self.button1Clicked()
25
-
26
-        button1 = QPushButton("클릭", self)
27
-        button1.move(20, 90)
28
-        button1.clicked.connect(self.button1Clicked)
29
-
30
-        button2 = QPushButton("지우기", self)
31
-        button2.move(130, 90)
32
-        button2.clicked.connect(self.button2Clicked)
33
-        
34
-        button3 = QPushButton("종료", self)
35
-        button3.move(240, 90)
36
-        button3.clicked.connect(QCoreApplication.instance().quit)
37
-
38
-    def button1Clicked(self):
39
-        self.label.setPixmap(self.img)
40
-
41
-    def button2Clicked(self):
42
-        self.label.clear()
43
-        
44
-if __name__ == "__main__":
45
-    app = QApplication(sys.argv)
46
-    mywindow = MyWindow()
47
-    mywindow.show()
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.initUI()
10
+
11
+    def initUI(self):
12
+        self.setWindowTitle('SWH Academy Window.')
13
+        self.setGeometry(200, 200, 360, 150)
14
+
15
+        self.label = QLabel("", self)
16
+        self.label.move(90, 20)
17
+        self.label.resize(172, 60)
18
+        self.img = QPixmap("poster.png")
19
+        self.button1Clicked()
20
+
21
+        button1 = QPushButton("클릭", self)
22
+        button1.move(20, 90)
23
+        button1.clicked.connect(self.button1Clicked)
24
+
25
+        button2 = QPushButton("지우기", self)
26
+        button2.move(130, 90)
27
+        button2.clicked.connect(self.button2Clicked)
28
+        
29
+        button3 = QPushButton("종료", self)
30
+        button3.move(240, 90)
31
+        button3.clicked.connect(QCoreApplication.instance().quit)
32
+
33
+    def button1Clicked(self):
34
+        self.label.setPixmap(self.img)
35
+
36
+    def button2Clicked(self):
37
+        self.label.clear()
38
+        
39
+if __name__ == "__main__":
40
+    app = QApplication(sys.argv)
41
+    mywindow = MyWindow()
42
+    mywindow.show()
48 43
     app.exec_()

+ 40
- 45
src/kr/co/swh/lecture/python/pyqt5/lineedit.py View File

@@ -1,46 +1,41 @@
1
-import sys
2
-from PyQt5.QtWidgets import *
3
-from PyQt5.QtCore import *
4
-
5
-class MyWindow(QMainWindow):
6
-    def __init__(self):
7
-        super().__init__()
8
-        self.title = 'SWH Academy Window.'
9
-        self.left = 200
10
-        self.top = 200
11
-        self.width = 360
12
-        self.height = 100
13
-        self.initUI()
14
-
15
-    def initUI(self):
16
-        self.setWindowTitle(self.title)
17
-        self.setGeometry(self.left, self.top, self.width, self.height)
18
-
19
-        self.label = QLabel("", self)
20
-        self.label.move(120, 20)
21
-        self.label.resize(150, 30)
22
-
23
-        self.lineEdit = QLineEdit("", self)
24
-        self.lineEdit.move(20, 50)
25
-        self.lineEdit.textChanged.connect(self.lineEditChanged)
26
-
27
-        button2 = QPushButton("지우기", self)
28
-        button2.move(130, 50)
29
-        button2.clicked.connect(self.button2Clicked)
30
-        
31
-        button3 = QPushButton("종료", self)
32
-        button3.move(240, 50)
33
-        button3.clicked.connect(QCoreApplication.instance().quit)
34
-
35
-    def lineEditChanged(self):
36
-        self.label.setText(self.lineEdit.text())
37
-
38
-    def button2Clicked(self):
39
-        self.label.clear()
40
-        self.lineEdit.clear()
41
-        
42
-if __name__ == "__main__":
43
-    app = QApplication(sys.argv)
44
-    mywindow = MyWindow()
45
-    mywindow.show()
1
+import sys
2
+from PyQt5.QtWidgets import *
3
+from PyQt5.QtCore import *
4
+
5
+class MyWindow(QMainWindow):
6
+    def __init__(self):
7
+        super().__init__()
8
+        self.initUI()
9
+
10
+    def initUI(self):
11
+        self.setWindowTitle('SWH Academy Window.')
12
+        self.setGeometry(200, 200, 360, 100)
13
+
14
+        self.label = QLabel("", self)
15
+        self.label.move(120, 20)
16
+        self.label.resize(150, 30)
17
+
18
+        self.lineEdit = QLineEdit("", self)
19
+        self.lineEdit.move(20, 50)
20
+        self.lineEdit.textChanged.connect(self.lineEditChanged)
21
+
22
+        button2 = QPushButton("지우기", self)
23
+        button2.move(130, 50)
24
+        button2.clicked.connect(self.button2Clicked)
25
+        
26
+        button3 = QPushButton("종료", self)
27
+        button3.move(240, 50)
28
+        button3.clicked.connect(QCoreApplication.instance().quit)
29
+
30
+    def lineEditChanged(self):
31
+        self.label.setText(self.lineEdit.text())
32
+
33
+    def button2Clicked(self):
34
+        self.label.clear()
35
+        self.lineEdit.clear()
36
+        
37
+if __name__ == "__main__":
38
+    app = QApplication(sys.argv)
39
+    mywindow = MyWindow()
40
+    mywindow.show()
46 41
     app.exec_()

+ 52
- 57
src/kr/co/swh/lecture/python/pyqt5/radiobutton.py View File

@@ -1,58 +1,53 @@
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
-        groupBox = QGroupBox("우리집 고양이들", self)
29
-        groupBox.move(10, 490)
30
-        groupBox.resize(580, 50)
31
-        
32
-        self.radioButton1 = QRadioButton("코야", self)
33
-        self.radioButton1.move(20, 500)
34
-        self.radioButton1.setChecked(True)
35
-        self.radioButton1.clicked.connect(self.radioButtonClicked)
36
-        self.radioButtonClicked()
37
-        
38
-        self.radioButton2 = QRadioButton("레종", self)
39
-        self.radioButton2.move(130, 500)
40
-        self.radioButton2.clicked.connect(self.radioButtonClicked)
41
-        
42
-        self.radioButton3 = QRadioButton("유키", self)
43
-        self.radioButton3.move(240, 500)
44
-        self.radioButton3.clicked.connect(self.radioButtonClicked)
45
-
46
-    def radioButtonClicked(self):
47
-        if self.radioButton1.isChecked():
48
-            self.label.setPixmap(self.catImg1)
49
-        elif self.radioButton2.isChecked():
50
-            self.label.setPixmap(self.catImg2)
51
-        else:
52
-            self.label.setPixmap(self.catImg3)
53
-        
54
-if __name__ == "__main__":
55
-    app = QApplication(sys.argv)
56
-    mywindow = MyWindow()
57
-    mywindow.show()
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.initUI()
10
+
11
+    def initUI(self):
12
+        self.setWindowTitle('SWH Academy Window.')
13
+        self.setGeometry(200, 100, 600, 550)
14
+
15
+        self.label = QLabel("", self)
16
+        self.label.move(10, 20)
17
+        self.label.resize(580, 460)
18
+        
19
+        self.catImg1 = QPixmap("cat1.jpeg")
20
+        self.catImg2 = QPixmap("cat2.jpg")
21
+        self.catImg3 = QPixmap("cat3.jpg")
22
+
23
+        groupBox = QGroupBox("우리집 고양이들", self)
24
+        groupBox.move(10, 490)
25
+        groupBox.resize(580, 50)
26
+        
27
+        self.radioButton1 = QRadioButton("코야", self)
28
+        self.radioButton1.move(20, 500)
29
+        self.radioButton1.setChecked(True)
30
+        self.radioButton1.clicked.connect(self.radioButtonClicked)
31
+        self.radioButtonClicked()
32
+        
33
+        self.radioButton2 = QRadioButton("레종", self)
34
+        self.radioButton2.move(130, 500)
35
+        self.radioButton2.clicked.connect(self.radioButtonClicked)
36
+        
37
+        self.radioButton3 = QRadioButton("유키", self)
38
+        self.radioButton3.move(240, 500)
39
+        self.radioButton3.clicked.connect(self.radioButtonClicked)
40
+
41
+    def radioButtonClicked(self):
42
+        if self.radioButton1.isChecked():
43
+            self.label.setPixmap(self.catImg1)
44
+        elif self.radioButton2.isChecked():
45
+            self.label.setPixmap(self.catImg2)
46
+        else:
47
+            self.label.setPixmap(self.catImg3)
48
+        
49
+if __name__ == "__main__":
50
+    app = QApplication(sys.argv)
51
+    mywindow = MyWindow()
52
+    mywindow.show()
58 53
     app.exec_()