<reponame>liyu13264/PyQt5_Practice<filename>src/code.py
import sys

from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QHBoxLayout, QPushButton


class QuitApplication(QMainWindow):

    def __init__(self):
        super(QuitApplication, self).__init__()
        self.resize(300, 120)
        self.setWindowTitle('quit the application')

        # add one button
        self.init()
        self.show()

    def init(self):
        button = QPushButton('quit')
        button.clicked.connect(self.onClickButton)
        layout = QHBoxLayout()
        layout.addWidget(button)

        mainFrame = QWidget()
        mainFrame.setLayout(layout)

        self.setCentralWidget(mainFrame)

    def onClickButton(self):
        print(self.sender().text() + 'press this button')
        QApplication.instance().quit()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QuitApplication()
    sys.exit(app.exec_())

import sys

from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QHBoxLayout, QPushButton


class QuitApplication(QMainWindow):

    def __init__(self):
        super(QuitApplication, self).__init__()
        self.resize(300, 120)
        self.setWindowTitle('quit the application')

        # add one button
        self.init()
        self.show()

    def init(self):
        button = QPushButton('quit')
        button.clicked.connect(self.onClickButton)
        layout = QHBoxLayout()
        layout.addWidget(button)

        mainFrame = QWidget()
        mainFrame.setLayout(layout)

        self.setCentralWidget(mainFrame)

    def onClickButton(self):
        print(self.sender().text() + 'press this button')
        QApplication.instance().quit()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QuitApplication()
    sys.exit(app.exec_())
# add one button