如何在弹出窗口内制作一个按钮,以关闭所述弹出窗口?

时间:2019-10-26 15:20:42

标签: pyqt5

我知道有人问过这个问题,但是我仍然无法解决这个问题。我创建了一个弹出窗口,并在其中添加了一个按钮。我希望按钮仅关闭弹出窗口。现在,它关闭了所有内容。

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QPushButton, QGridLayout, QWidget, QLabel

class NewWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super(NewWindow, self).__init__(parent)
        self.Button = QPushButton('Close')
        centralWidget = QWidget()
        self.setCentralWidget(centralWidget)
        self.layout = QGridLayout(centralWidget)
        self.layout.addWidget(self.Button)
        self.Button.clicked.connect(self.close)

    def close(self):
        sys.exit()


class MyWindow(QtWidgets.QMainWindow, QPushButton):
    def __init__(self):
        super(MyWindow, self).__init__()
        centralWidget = QWidget()
        self.setCentralWidget(centralWidget)
        self.setWindowTitle("ASSET")
        self.Button = QPushButton('Action',self)
        self.Button.clicked.connect(self.Action)
        self.layout = QGridLayout(centralWidget)
        self.layout.addWidget(self.Button)

        self.new_window = NewWindow(self)

    def Action(self):
        self.new_window.show()

if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())

0 个答案:

没有答案