pythonpyqt4multi-window

maximum recursion depth exceeded in python multiple dialog


# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore

class Window_Test3(QtGui.QDialog):

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        global progress_flag
        **self.Next_Window = Window_Test1()   # Return Window_Test1() but RuntimeError: maximum recursion depth exceeded**

  self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|QtCore.Qt.WindowTitleHint|QtCore.Qt.WindowMaximizeButtonHint)
        self.setGeometry(0, 0, 800,480)
        self.setWindowTitle('TEST PROCESSING')

        quit = QtGui.QPushButton('Close', self)

        quit.setGeometry(10, 10, 60, 35)

        test = QtGui.QPushButton('TEST 3', self)
        test.setGeometry(100, 200, 200, 100)


        self.connect(quit, QtCore.SIGNAL('clicked()'),self.reject)
        self.connect(test, QtCore.SIGNAL('clicked()'), self.nextWindow)

    def nextWindow(self):

        self.Next_Window.show()

class Window_Test2(QtGui.QDialog):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        global progress_flag
        self.Window3 = Window_Test3()

        self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|QtCore.Qt.WindowTitleHint|QtCore.Qt.WindowMaximizeButtonHint)
        self.setGeometry(0, 0, 800, 480)
        self.setWindowTitle('TEST PROCESSING')

        self.quit = QtGui.QPushButton('Close', self)
        self.quit.setGeometry(10, 10, 60, 35)

        test = QtGui.QPushButton('TEST 2', self)
        test.setGeometry(250, 220, 200, 100)

        self.connect(self.quit, QtCore.SIGNAL('clicked()'),self.reject)

        self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)

    def nextWindow(self):

        self.Window3.show()

class Window_Test1(QtGui.QDialog):

    def __init__(self):
        QtGui.QWidget.__init__(self)

        self.Window2 = Window_Test2()

        self.setGeometry(0, 0, 800, 480)
        self.setWindowTitle('TEST PROCESSING' )

        test = QtGui.QPushButton('TEST', self)
        test.setGeometry(100,100,100,100)

        quit = QtGui.QPushButton('Close', self)
        quit.setGeometry(10, 10, 60, 35)

        self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)

        self.connect(quit, QtCore.SIGNAL('clicked()'), self.reject)

    def nextWindow(self):
        self.Window2.show()

if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    Window1 = Window_Test1()
    Window1.show()
    sys.exit(app.exec_())

Solution

  • Create a placeholder self.next_Window for the next window and fill it in after creating all 3 windows

    # -*- coding: utf-8 -*-
    import sys
    from PyQt4 import QtGui, QtCore
    
    class Window_Test3(QtGui.QDialog):
    
        def __init__(self, parent=None):
            QtGui.QWidget.__init__(self, parent)
            global progress_flag
            self.next_Window = None
    
            self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|
                                QtCore.Qt.WindowTitleHint|
                                QtCore.Qt.WindowMaximizeButtonHint)
            self.setGeometry(0, 0, 800,480)
            self.setWindowTitle('TEST PROCESSING')
    
            quit = QtGui.QPushButton('Close', self)
    
            quit.setGeometry(10, 10, 60, 35)
    
            test = QtGui.QPushButton('TEST 3', self)
            test.setGeometry(100, 200, 200, 100)
    
    
            self.connect(quit, QtCore.SIGNAL('clicked()'),self.reject)
            self.connect(test, QtCore.SIGNAL('clicked()'), self.nextWindow)
    
        def nextWindow(self):
            self.next_Window.show()
        def setNextWindow(self, nextWindow):
            self.next_Window = nextWindow
    
    class Window_Test2(QtGui.QDialog):
        def __init__(self):
            QtGui.QWidget.__init__(self)
            global progress_flag
            self.next_Window = None
    
            self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|
                                QtCore.Qt.WindowTitleHint|
                                QtCore.Qt.WindowMaximizeButtonHint)
            self.setGeometry(0, 0, 800, 480)
            self.setWindowTitle('TEST PROCESSING')
    
            self.quit = QtGui.QPushButton('Close', self)
            self.quit.setGeometry(10, 10, 60, 35)
    
            test = QtGui.QPushButton('TEST 2', self)
            test.setGeometry(250, 220, 200, 100)
    
            self.connect(self.quit, QtCore.SIGNAL('clicked()'),self.reject)
    
            self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
    
        def nextWindow(self):
            self.next_Window.show()
        def setNextWindow(self, nextWindow):
            self.next_Window = nextWindow
    
    class Window_Test1(QtGui.QDialog):
    
        def __init__(self):
            QtGui.QWidget.__init__(self)
            self.next_Window = None
    
            self.setGeometry(0, 0, 800, 480)
            self.setWindowTitle('TEST PROCESSING' )
    
            test = QtGui.QPushButton('TEST', self)
            test.setGeometry(100,100,100,100)
    
            quit = QtGui.QPushButton('Close', self)
            quit.setGeometry(10, 10, 60, 35)
    
            self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
            self.connect(quit, QtCore.SIGNAL('clicked()'), self.reject)
    
        def nextWindow(self):
            self.next_Window.show()
        def setNextWindow(self, nextWindow):
            self.next_Window = nextWindow
    
    if __name__ == '__main__':
    
        app = QtGui.QApplication(sys.argv)
        Window1 = Window_Test1()
        Window2 = Window_Test2()
        Window3 = Window_Test3()
        Window1.setNextWindow(Window2)
        Window2.setNextWindow(Window3)
        Window3.setNextWindow(Window1)
        Window1.show()
        sys.exit(app.exec_())