Browse Source

label image add

tobby48 6 years ago
parent
commit
c15e56ead9

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

@@ -0,0 +1,49 @@
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
+        self.label.show()
26
+
27
+        button1 = QPushButton("클릭", self)
28
+        button1.move(20, 90)
29
+        button1.clicked.connect(self.button1Clicked)
30
+
31
+        button2 = QPushButton("지우기", self)
32
+        button2.move(130, 90)
33
+        button2.clicked.connect(self.button2Clicked)
34
+        
35
+        button3 = QPushButton("종료", self)
36
+        button3.move(240, 90)
37
+        button3.clicked.connect(QCoreApplication.instance().quit)
38
+
39
+    def button1Clicked(self):
40
+        self.label.setPixmap(self.img)
41
+
42
+    def button2Clicked(self):
43
+        self.label.clear()
44
+        
45
+if __name__ == "__main__":
46
+    app = QApplication(sys.argv)
47
+    mywindow = MyWindow()
48
+    mywindow.show()
49
+    app.exec_()

BIN
src/kr/co/swh/lecture/python/pyqt5/poster.png View File


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

@@ -0,0 +1,46 @@
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()
46
+    app.exec_()