【PyQt5】{1} —— 把代碼封裝成類

# -*- coding: utf-8 -*-
"""
Created on Fri May  8 22:30:19 2020

@author: Giyn
"""

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton


class Simple_Window(QWidget):
    def __init__(self):
        super(Simple_Window, self).__init__() # 使用super函數可以實現子類使用父類的方法
        self.label = QLabel("This is a Label", self) # self是指定的父類Simple_Window,表示QLabel屬於Simple_Window窗口
        
        
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Simple_Window()
    window.show()
    sys.exit(app.exec())

Output:

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章