瀏覽代碼

label add

tobby48 6 年之前
父節點
當前提交
66edebbd6a
共有 1 個檔案被更改,包括 47 行新增0 行删除
  1. 47
    0
      src/kr/co/swh/lecture/python/pyqt5/label.py

+ 47
- 0
src/kr/co/swh/lecture/python/pyqt5/label.py 查看文件

@@ -0,0 +1,47 @@
1
+import sys
2
+from PyQt5.QtWidgets import *
3
+from PyQt5.QtGui import QIcon
4
+from PyQt5.QtCore 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 = 100
14
+        self.initUI()
15
+
16
+    def initUI(self):
17
+        self.setWindowTitle(self.title)
18
+        self.setWindowIcon(QIcon('favicon.ico'))
19
+        self.setGeometry(self.left, self.top, self.width, self.height)
20
+
21
+        self.label = QLabel("", self)
22
+        self.label.move(120, 20)
23
+        self.label.resize(150, 30)
24
+
25
+        button1 = QPushButton("클릭", self)
26
+        button1.move(20, 50)
27
+        button1.clicked.connect(self.button1Clicked)
28
+
29
+        button2 = QPushButton("지우기", self)
30
+        button2.move(130, 50)
31
+        button2.clicked.connect(self.button2Clicked)
32
+        
33
+        button3 = QPushButton("종료", self)
34
+        button3.move(240, 50)
35
+        button3.clicked.connect(QCoreApplication.instance().quit)
36
+
37
+    def button1Clicked(self):
38
+        self.label.setText("버튼이 클릭되었습니다.")
39
+
40
+    def button2Clicked(self):
41
+        self.label.clear()
42
+        
43
+if __name__ == "__main__":
44
+    app = QApplication(sys.argv)
45
+    mywindow = MyWindow()
46
+    mywindow.show()
47
+    app.exec_()