PyQt window closes immediately after opening

You need to keep a reference to the opened window, otherwise it goes out of scope and is garbage collected, which will destroy the underlying C++ object also. Try:

def Start():
    m = myWindow()
    m.show()
    return m


class myWindow():....

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    window = Start()
    app.exec_()

Leave a Comment