First, you must name your GUI classes so that they have a different name, not a common one, so that you can distinguish them.
Why do you need this? Well, simply because it makes sense - if each class represents a different type of dialogue, then it is a different type - and it should be called differently. Some names are / could be: QMessageBox , AboutBox , AddUserDialog , etc.
In Acceuil_start.py (you must also rename the class to another module).
import sys from PyQt4 import QtCore, QtGui from Authentification_1 import Ui_Fenetre_auth from Acceuil_2 import Ui_MainWindow class Acceuil(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = Acceuil() myapp.show() sys.exit(app.exec_())
in the parent class, when you want to create a window, you are close (but it should work anyway):
def authentifier(val):
About the parent problem: if your widget / window creates another widget, setting the creator object as a parent is always a good idea (except in individual cases), and you should read this to understand why this is:
QObjects are organized in object trees. When you create a QObject with another object as a parent, it is added to the children () parent list and deleted when the parent object. It turns out that this approach is very well suited for the needs of GUI objects. For example, QShortcut (keyboard shortcut) is a child of the corresponding window, so when the user closes this window, shorcut is also deleted.
Edit - minimum working example
To find out what I'm trying to tell you, I built a simple example. You have two classes - MainWindow and ChildWindow . Each class can work without another class, creating separate QApplication objects. But if you import ChildWindow into MainWindow , you will create ChildWindow in the slot connected to the timer timer, which will start in 5 seconds.
MainWindow.py:
import sys from PyQt4 import QtCore, QtGui from ChildWindow import ChildWindow class MainWindow(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) QtCore.QTimer.singleShot(5000, self.showChildWindow) def showChildWindow(self): self.child_win = ChildWindow(self) self.child_win.show() if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = MainWindow() myapp.show() sys.exit(app.exec_())
ChildWindow.py:
import sys from PyQt4 import QtCore, QtGui class ChildWindow(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.setWindowTitle("Child Window!") if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = ChildWindow() myapp.show() sys.exit(app.exec_())