# -*- 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_())
Asked
Active
Viewed 269 times
-1
-
Welcome to SO. I formatted your code so that it renders properly (indent all code lines by four spaces to do that). However, it is very unclear to me what the problem with this code is. Can you add any errors you see, a description of what you expect to happen and what actually happens? You can use the edit button under your question to add this information. – m00am Jul 15 '18 at 16:12
-
lass Window_Test3(QtGui.QDialog): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) global progress_flag => Error **self.Next_Window = Window_Test1() The error contents are as follows.=> # Return Window_Test1() but RuntimeError: maximum recursion depth exceeded** – 정유한 Jul 16 '18 at 11:44
3 Answers
1
Your code recursively initializes new objects.
Window_Test1 calls Window_Test2, which calls Window_Test3, which calls Window_Test1, which calls Window_Test2, which calls Window_Test3, which calls Window_Test1, which... you get the point.
You'll want to either defer the initialization of those objects to when they're actually needed (so not in __init__
), or maybe have single instances of all three windows that are referred to.

AKX
- 152,115
- 15
- 115
- 172
-
What if you make them into an inner class where they will be able to have access each other’s info, but I agree, delay the creation in __init__ then – skarchmit Jul 15 '18 at 16:20
-
There should be only one window instead of three. def nextWindow (self): self.next_Window.show () self.actionEvent (self.reject ()) # Delete current screen def setNextWindow (self, nextWindow): self.next_Window = nextWindow That is, you add self.actionEvent (self.reject ()), One screen is output. However, there is a slight jitter when switching the screen. – 정유한 Jul 16 '18 at 12:39
0
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_())

rioV8
- 24,506
- 3
- 32
- 49
0
There should be only one window instead of three.
def nextWindow (self):
self.next_Window.show()
self.actionEvent (self.reject ()) # Delete current screen
def setNextWindow (self, nextWindow):
self.next_Window = nextWindow
That is, you add self.actionEvent(self.reject ())
,
One screen is output.
However, there is a slight jitter when switching the screen.