tobby48 6 years ago
parent
commit
9a6aa97558

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

@@ -1,48 +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.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()
48
-    app.exec_()
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
+    window = MyWindow()
47
+    window.show()
48
+    sys.exit(app.exec_())

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

@@ -1,56 +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.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, text):
34
-        if text == '코야':
35
-            self.label.setPixmap(self.catImg1)
36
-        elif text == '레종':
37
-            self.label.setPixmap(self.catImg2)
38
-        else:
39
-            self.label.setPixmap(self.catImg3)
40
-    
41
-'''
42
-        self.comboBoxChanged()
43
-    def comboBoxChanged(self):
44
-        if self.comboBox.currentText() == '코야':
45
-            self.label.setPixmap(self.catImg1)
46
-        elif self.comboBox.currentText() == '레종':
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()
56
-    app.exec_()
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, text):
34
+        if text == '코야':
35
+            self.label.setPixmap(self.catImg1)
36
+        elif text == '레종':
37
+            self.label.setPixmap(self.catImg2)
38
+        else:
39
+            self.label.setPixmap(self.catImg3)
40
+    
41
+'''
42
+        self.comboBoxChanged()
43
+    def comboBoxChanged(self):
44
+        if self.comboBox.currentText() == '코야':
45
+            self.label.setPixmap(self.catImg1)
46
+        elif self.comboBox.currentText() == '레종':
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
+    window = MyWindow()
55
+    window.show()
56
+    sys.exit(app.exec_())

+ 47
- 0
src/kr/co/swh/lecture/python/pyqt5/dial.py View File

@@ -0,0 +1,47 @@
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, 400, 100)
13
+
14
+        self.spinBox = QSpinBox(self)
15
+        self.spinBox.move(20, 20)
16
+        self.spinBox.resize(80, 20)
17
+        self.spinBox.valueChanged.connect(self.spinBoxChanged)
18
+
19
+        self.statusBar = QStatusBar(self)
20
+        self.setStatusBar(self.statusBar)
21
+        
22
+        self.slider = QSlider(Qt.Horizontal, self)
23
+        self.slider.move(150, 20)
24
+        self.slider.setRange(0, 100)
25
+        self.slider.valueChanged.connect(self.sliderChanged)
26
+        
27
+        self.dial = QDial(self)
28
+        self.dial.move(300, 20)
29
+        self.dial.setRange(0, 100)
30
+        self.dial.resize(50, 50)
31
+        self.dial.valueChanged.connect(self.slider.setValue)
32
+
33
+    def spinBoxChanged(self):
34
+        value = self.spinBox.value()
35
+        self.slider.setValue(value)
36
+        self.statusBar.showMessage('%d' % value)
37
+    
38
+    def sliderChanged(self):
39
+        value = self.slider.value()
40
+        self.spinBox.setValue(value)
41
+        self.statusBar.showMessage('%d' % value)
42
+        
43
+if __name__ == "__main__":
44
+    app = QApplication(sys.argv)
45
+    window = MyWindow()
46
+    window.show()
47
+    sys.exit(app.exec_())

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

@@ -1,40 +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.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()
40
-    app.exec_()
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
+    window = MyWindow()
39
+    window.show()
40
+    sys.exit(app.exec_())

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

@@ -1,43 +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.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()
43
-    app.exec_()
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
+    window = MyWindow()
42
+    window.show()
43
+    sys.exit(app.exec_())

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

@@ -1,41 +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.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()
41
-    app.exec_()
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
+    window = MyWindow()
40
+    window.show()
41
+    sys.exit(app.exec_())

+ 2
- 3
src/kr/co/swh/lecture/python/pyqt5/mainwindow3.py View File

@@ -22,10 +22,9 @@ class MyWindow(QMainWindow):
22 22
         p = self.palette()
23 23
         p.setColor(self.backgroundRole(), Qt.darkRed)
24 24
         self.setPalette(p)
25
-        
26
-        self.show()
27 25
      
28 26
 if __name__ == '__main__':
29 27
     app = QApplication(sys.argv)
30
-    ex = MyWindow()
28
+    window = MyWindow()
29
+    window.show()
31 30
     sys.exit(app.exec_())

+ 1
- 1
src/kr/co/swh/lecture/python/pyqt5/pushbutton2.py View File

@@ -20,4 +20,4 @@ if __name__ == "__main__":
20 20
     app = QApplication(sys.argv)
21 21
     window = MyWindow()
22 22
     window.show()
23
-    app.exec_()
23
+    sys.exit(app.exec_())

+ 1
- 1
src/kr/co/swh/lecture/python/pyqt5/pushbutton3.py View File

@@ -18,4 +18,4 @@ if __name__ == "__main__":
18 18
     app = QApplication(sys.argv)
19 19
     window = MyWindow()
20 20
     window.show()
21
-    app.exec_()
21
+    sys.exit(app.exec_())

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

@@ -1,53 +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.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()
53
-    app.exec_()
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
+    window = MyWindow()
52
+    window.show()
53
+    sys.exit(app.exec_())

+ 45
- 0
src/kr/co/swh/lecture/python/pyqt5/spinboxslider.py View File

@@ -0,0 +1,45 @@
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, 300, 100)
13
+
14
+        self.spinBox = QSpinBox(self)
15
+        self.spinBox.move(20, 20)
16
+        self.spinBox.resize(80, 22)
17
+        self.spinBox.setValue(10)
18
+        self.spinBox.setSingleStep(10)
19
+        self.spinBox.setMinimum(1)
20
+        self.spinBox.setMaximum(100)
21
+        self.spinBox.valueChanged.connect(self.spinBoxChanged)
22
+
23
+        self.statusBar = QStatusBar(self)
24
+        self.setStatusBar(self.statusBar)
25
+        
26
+        self.slider = QSlider(Qt.Horizontal, self)
27
+        self.slider.move(150, 20)
28
+        self.slider.setRange(0, 100)
29
+        self.slider.valueChanged.connect(self.sliderChanged)
30
+        
31
+    def spinBoxChanged(self):
32
+        value = self.spinBox.value()
33
+        self.slider.setValue(value)
34
+        self.statusBar.showMessage('%d' % value)
35
+    
36
+    def sliderChanged(self):
37
+        value = self.slider.value()
38
+        self.spinBox.setValue(value)
39
+        self.statusBar.showMessage('%d' % value)
40
+        
41
+if __name__ == "__main__":
42
+    app = QApplication(sys.argv)
43
+    window = MyWindow()
44
+    window.show()
45
+    sys.exit(app.exec_())