'How do I open multiple windows in PyQt5

I am trying to make a program with multiple windows so that the next window will open after clicking a pushbutton. The first window works just fine and the second window opens but pushbuttons don't work in the second window.

The buttons in the second window make the program shut down when the window is opened from the first one but when the second window is opened on its own and not from the first window, it works.

Here is the important parts from the class for the first window:

class Ui_mainWindow(object):

    def openCreateAccount(self):
        from createAccount import Ui_createAccount
        self.window1= QtWidgets.QDialog()
        self.ui= Ui_createAccount()
        self.ui.setupUi(self.window1)
        self.window1.show()
        mainWindow.hide()

    def setupUi(self, mainWindow):
        self.buttonCreateAccount = QtWidgets.QPushButton(self.centralwidget)
        self.buttonCreateAccount.clicked.connect(self.openCreateAccount)

And here is the important parts of the class for the second window:

class Ui_createAccount(object):

    def clickEnter(self):
        from home import Ui_home
        self.window2= QtWidgets.QDialog()
        self.ui= Ui_home()
        self.ui.setupUi(self.window2)
        self.window2.show()
        createAccount.hide() 

    def setupUi(self, createAccount):
        self.buttonHome= QtWidgets.QPushButton(self.centralwidget)
        self.buttonHome.clicked.connect(self.clickEnter)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source