I have been trying to develop a multi-window application using the PyQt5 library. I wanted to have a second window dedicated for separate features. I was able to switch from the main window to the secondary window without any problems. However after attempting to switch back, I got the Recursion Error exception. Here is the relevant code:
import os
import sys
from functools import partial
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication, QFrame, QMessageBox, QMenu
class IpLogger(QMainWindow):
def __init__(self):
super(IpLogger, self).__init__()
self.setWindowTitle("Main window")
self.setFixedSize(648, 228)
self.setWindowIcon(QtGui.QIcon("data\\icon\\WiFicon.ico"))
self.loggerUI()
def loggerUI(self):
#Define font variable
font = QtGui.QFont()
#Button leading to second window
self.mediaBtn = QtWidgets.QPushButton(self)
self.mediaBtn.setGeometry(QtCore.QRect(10, 180, 181, 41))
font.setPointSize(10)
self.mediaBtn.setFont(font)
self.mediaBtn.setObjectName("mediaBtn")
self.mediaBtn.setText("Social Media")
self.mediaBtn.clicked.connect(partial(self.showWindow, Media()))
#Switching windows
def showWindow(self, window):
self.win = window
self.win.show()
self.close()
class Media(QMainWindow):
def __init__(self):
super(Media, self).__init__()
self.setWindowTitle("Second window")
self.setFixedSize(300, 180)
self.setWindowIcon(QtGui.QIcon("data\\icon\\WiFicon.ico"))
self.mediaUI()
def mediaUI(self):
#Variables
font = QtGui.QFont()
#Button leading back to the main menu
self.backBtn = QtWidgets.QPushButton(self)
self.backBtn.setGeometry(QtCore.QRect(130, 123, 40, 40))
font.setFamily("Segoe UI")
font.setPointSize(10)
self.backBtn.setFont(font)
self.backBtn.setObjectName("backBtn")
self.backBtn.setStyleSheet("background-color: rgb(69, 69, 69, 0)")
self.backBtn.setIcon(QtGui.QIcon("data\\icon\\back.png"))
self.backBtn.setIconSize(QtCore.QSize(40, 40))
self.backBtn.clicked.connect(partial(self.showWindow, IpLogger()))
#Switching windows
def showWindow(self, window):
self.win = window
self.win.show()
self.close()
def window():
app = QApplication(sys.argv)
win = IpLogger()
win.show()
sys.exit(app.exec_())
window()