0

I know this question has been asked, but I still cannot get this to work. I created a popup window and added a button to it. I want the button to only close the popup window. Right now it closes everything.

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_())
Paul
  • 107
  • 8

0 Answers0