P
P
Ping Wins2019-05-03 14:50:55
Python
Ping Wins, 2019-05-03 14:50:55

How to create a child window in pyqt5?

I created 2 simple windows in Qt Designer:
5ccc2a486749d542940574.png
Next, I decided to try by pressing the "Deposit account" button, close the main window and open 2:
5ccc2a6706f77209168735.png
But when I create 2 windows, I have nothing in it and it does not match its size
Here is the code that I wrote :

import sys
import first_window
import double_window

from PyQt5 import QtCore, QtGui, QtWidgets

class TwoWindow(QtWidgets.QMainWindow, double_window.Ui_MainWindow):
        def __inir__(self):
            super().__init__()
            self.setupUi(self)
            #self.pushButton.clicked.connect(self.check2)

        

class OneWindow(QtWidgets.QMainWindow, first_window.Ui_MainWindow):
    def __init__(self, parent = None):
        super().__init__(parent)
        self.setupUi(self)
        self.twoWindow = None
        self.pushButton.clicked.connect(self.check)

    def check(self):
        #print (5)
        self.close()
        self.twoWindow = TwoWindow()
        self.twoWindow.show()
        

def main():
    app = QtWidgets.QApplication(sys.argv)
    window = OneWindow()
    window.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()

What is the error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Bezh, 2019-05-03
@PingWins

How to pop up a new window when a Button is clicked?
In general, you have an error

class TwoWindow(QtWidgets.QMainWindow, double_window.Ui_MainWindow):
        def __inir__(self):

There should be __init__
Your version is quite working, just a typo

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question