전공 과목 이수1👨‍💻/파이썬

11주차과제) spyder 과제

천숭이 2020. 11. 19. 15:09

(1) push 버튼 누르면 창꺼지면서 print출력

# -*- coding: utf-8 -*-

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QCoreApplication

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setGeometry(800,250,300,170)
        self.setWindowTitle("QPushButton")
        self.UI()
        
    def UI(self):
        self.text=QLabel("Don't Push the button", self)
        enterPush=QPushButton("Push",self)
        self.text.move(100, 50)
        enterPush.move(120,85)
        enterPush.clicked.connect(self.pushFunc)
        self.show()
        
    def pushFunc(self):
        print("The window has been close.")
        QCoreApplication.instance().quit()

def main():
    App= QApplication(sys.argv)
    window=Window()
    sys.exit(App.exec_())
    
if __name__=='__main__':
    main()