tobby48 vor 6 Jahren
Ursprung
Commit
15d8d00ed2

src/kr/co/swh/lecture/python/pyqt5/window-helloworld2.py → src/kr/co/swh/lecture/python/pyqt5/event-slot.py Datei anzeigen


src/kr/co/swh/lecture/python/pyqt5/window-event-slot.py → src/kr/co/swh/lecture/python/pyqt5/event-slot2.py Datei anzeigen


BIN
src/kr/co/swh/lecture/python/pyqt5/favicon.ico Datei anzeigen


src/kr/co/swh/lecture/python/pyqt5/window-helloworld.py → src/kr/co/swh/lecture/python/pyqt5/helloworld.py Datei anzeigen


+ 19
- 0
src/kr/co/swh/lecture/python/pyqt5/mainwindow.py Datei anzeigen

@@ -0,0 +1,19 @@
1
+import sys
2
+from PyQt5.QtWidgets import *
3
+from PyQt5.QtGui import QIcon
4
+from PyQt5.QtCore import Qt
5
+
6
+app = QApplication(sys.argv)
7
+window = QMainWindow()
8
+
9
+window.setWindowTitle("SWH")
10
+window.setWindowIcon(QIcon('favicon.ico'))
11
+window.setGeometry(400, 300, 300, 100)
12
+
13
+window.setAutoFillBackground(True)
14
+p = window.palette()
15
+p.setColor(window.backgroundRole(), Qt.darkRed)
16
+window.setPalette(p)
17
+
18
+window.show()
19
+app.exec_()

src/kr/co/swh/lecture/python/pyqt5/window-main-window.py → src/kr/co/swh/lecture/python/pyqt5/mainwindow2.py Datei anzeigen

@@ -2,13 +2,13 @@ import sys
2 2
 from PyQt5.QtWidgets import *
3 3
         
4 4
 app = QApplication(sys.argv)
5
-mywindow = QMainWindow()
6
-button = QPushButton("눌러봐", mywindow)
5
+window = QMainWindow()
6
+button = QPushButton("눌러봐", window)
7 7
 button.move(50, 30)
8 8
 
9 9
 def click():
10 10
     QMessageBox.about(button, "메세지 박스", "눌렀어요.")
11 11
     
12 12
 button.clicked.connect(click)
13
-mywindow.show()
13
+window.show()
14 14
 app.exec_()

+ 23
- 0
src/kr/co/swh/lecture/python/pyqt5/mainwindow3.py Datei anzeigen

@@ -0,0 +1,23 @@
1
+import sys
2
+from PyQt5.QtWidgets import *
3
+from PyQt5.QtGui import QIcon
4
+ 
5
+class MyWindow(QWidget):
6
+    def __init__(self):
7
+        super().__init__()
8
+        self.title = 'SWH Academy Window.'
9
+        self.left = 200
10
+        self.top = 200
11
+        self.width = 400
12
+        self.height = 300
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
+        self.show()
19
+     
20
+if __name__ == '__main__':
21
+    app = QApplication(sys.argv)
22
+    ex = MyWindow()
23
+    sys.exit(app.exec_())

+ 67
- 0
src/kr/co/swh/lecture/python/pyqt5/painter.py Datei anzeigen

@@ -0,0 +1,67 @@
1
+import sys
2
+from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel
3
+from PyQt5.QtGui import QPainter, QColor, QPen
4
+from PyQt5.QtGui import QIcon
5
+from PyQt5.QtCore import Qt
6
+import random
7
+ 
8
+class MyWindow(QMainWindow):
9
+ 
10
+    def __init__(self):
11
+        super().__init__()
12
+        self.title = 'PyQt rectangle colors - pythonspot.com'
13
+        self.left = 10
14
+        self.top = 10
15
+        self.width = 440
16
+        self.height = 280
17
+        self.initUI()
18
+ 
19
+    def initUI(self):
20
+        self.setWindowTitle(self.title)
21
+        self.setGeometry(self.left, self.top, self.width, self.height)
22
+         
23
+        # Set window background color
24
+        self.setAutoFillBackground(True)
25
+        p = self.palette()
26
+        p.setColor(self.backgroundRole(), Qt.white)
27
+        self.setPalette(p)
28
+ 
29
+        # Add paint widget and paint
30
+        self.m = PaintWidget(self)
31
+        self.m.move(0,0)
32
+        self.m.resize(self.width,self.height)
33
+         
34
+        self.show()
35
+ 
36
+class PaintWidget(QWidget):
37
+    def paintEvent(self, event):
38
+        qp = QPainter(self)
39
+         
40
+        qp.setPen(Qt.black)
41
+        size = self.size()
42
+         
43
+        # Colored rectangles
44
+        qp.setBrush(QColor(200, 0, 0))
45
+        qp.drawRect(0, 0, 100, 100)
46
+         
47
+        qp.setBrush(QColor(0, 200, 0))
48
+        qp.drawRect(100, 0, 100, 100)
49
+         
50
+        qp.setBrush(QColor(0, 0, 200))
51
+        qp.drawRect(200, 0, 100, 100)
52
+         
53
+        # Color Effect
54
+        for i in range(0,100):
55
+            qp.setBrush(QColor(i*10, 0, 0))
56
+            qp.drawRect(10*i, 100, 10, 32)
57
+             
58
+            qp.setBrush(QColor(i*10, i*10, 0))
59
+            qp.drawRect(10*i, 100+32, 10, 32)
60
+             
61
+            qp.setBrush(QColor(i*2, i*10, i*1))
62
+            qp.drawRect(10*i, 100+64, 10, 32)
63
+ 
64
+if __name__ == '__main__':
65
+    app = QApplication(sys.argv)
66
+    ex = MyWindow()
67
+    sys.exit(app.exec_())

src/kr/co/swh/lecture/python/pyqt5/window-main-window2.py → src/kr/co/swh/lecture/python/pyqt5/pushbutton.py Datei anzeigen

@@ -1,9 +1,12 @@
1 1
 import sys
2 2
 from PyQt5.QtWidgets import *
3 3
 
4
-class WindowMessageBox(QMainWindow):
4
+class MyWindow(QMainWindow):
5 5
     def __init__(self):
6 6
         super().__init__()
7
+        self.initUI()
8
+        
9
+    def initUI(self):
7 10
         self.setWindowTitle("SWH")
8 11
 
9 12
         button = QPushButton("눌러봐", self)
@@ -15,6 +18,6 @@ class WindowMessageBox(QMainWindow):
15 18
 
16 19
 if __name__ == "__main__":
17 20
     app = QApplication(sys.argv)
18
-    mywindow = WindowMessageBox()
21
+    mywindow = MyWindow()
19 22
     mywindow.show()
20 23
     app.exec_()

+ 21
- 0
src/kr/co/swh/lecture/python/pyqt5/pushbutton2.py Datei anzeigen

@@ -0,0 +1,21 @@
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")
12
+
13
+        button = QPushButton("눌러봐", self)
14
+        button.move(50, 30)
15
+        button.clicked.connect(QCoreApplication.instance().quit)
16
+
17
+if __name__ == "__main__":
18
+    app = QApplication(sys.argv)
19
+    mywindow = MyWindow()
20
+    mywindow.show()
21
+    app.exec_()