PyQt5筆記(01) -- 建立空白窗體

目錄

PyQt5筆記(01) – 建立空白窗體
PyQt5筆記(02) – 按鈕點擊事件
PyQt5筆記(03) – 消息框
PyQt5筆記(04) – 文本框的使用
PyQt5筆記(05) – 絕對位置
爲了便於後期更新,全部目錄已彙總到一個連接,具體請移步到這裏html

正文

本節主要介紹如何建立一個PyQt的空白窗體app

 1 import sys
 2 from PyQt5.QtWidgets import QApplication, QWidget
 3 from PyQt5.QtGui import QIcon
 4 
 5 class App(QWidget):
 6 
 7     def __init__(self):
 8        super().__init__()
 9        self.titie = "QT simple window"
10        """用於設置窗體距屏幕左邊的距離"""
11        self.left = 20
12        """用於設置窗體距屏幕上方的距離"""
13        self.top = 20
14        """用於設置窗體的寬度"""
15        self.width = 640
16        """用於設置窗體的高度"""
17        self.height = 480
18        self.initUI()
19 
20     def initUI(self):
21         """設置窗體的標題"""
22         self.setWindowTitle(self.titie)
23         """使用setGeometry(left, top, width, height)方法設置窗體的參數"""
24         self.setGeometry(self.left, self.top, self.width, self.height)
25         """經過調用show()函數來顯示窗口"""
26         self.show()
27 
28 if __name__ == '__main__':
29     app = QApplication(sys.argv)
30     ex = App()
31     sys.exit(app.exec_())
相關文章
相關標籤/搜索