PyQt5: Closing Main Window from Another File - Multiple Instance Issue
Unsolved
Qt for Python
-
I'm encountering a challenge in my PyQt5 application. I have a main window created in one file (common_methods.py). I want to close this window from another file (Main_controller.py). However, when I attempt to close it, unable to close it
Below is my code,
common_methods.py
class Common_methods: def __init__(self): pass def mainScreen(self): # Code to create and show the main window # ... return mainWindow
Main_controller.py
class Main_controller: def __init__(self): pass def newPrj(self): common_method_instance = Common_methods() mainScreen_instance = common_method_instance.mainScreen() # Calling mainScreen again? mainScreen_instance.close()
-
@shashanksd
Each time you callcommon_method_instance.mainScreen()
that creates a newmainScreen_instance
assuming your comment# Code to create and show the main window
is true, and it is that which you close.
I'm not saying whether your architecture is good, it's odd, but given what you are doing you need to keep a reference to the initially created main window around somewhere.