Multiple windows in PyQt4?

I just started using pyqt4. I followed the tutorial ( http://zetcode.com/tutorials/pyqt4/ ) One thing that puzzles me is this part:

def main():
    app = QtGui.QApplication(sys.argv)
    ex = GUI()
    sys.exit(app.exec())

And the reason for this I will explain here:

I made a small program that opens four more windows besides the first main window. So I tried to reproduce what I saw while working with the main window, and created a class for each new window and tried to do it using the above. Currently it looks like this:

def main2():
    #app = QtGui.QApplication(sys.argv)
    ex2 = Settings()
    sys.exit(app.exec())

As you can see, I changed it. If I left the first line in the function without commenting, the program will crash. I tried to do without sys.exit (app.exec _ ()) -part, but that would only make the new window close the milliseconds after it was shown. Thus, everything works and works. Only a command window displays an error message. I don’t know how to fix it, because I can’t delete the last line, and I don’t know what to replace with “application” .

, , , , , . - , . , - , :)

( )!

, :

class GUI(QtGui.QMainWindow):
    def __init__(self):
        super(GUI, self).__init__()
        self.initUI()

class Settings(QtGui.QWidget):
    def __init__(self):
        super(Settings, self).__init__()
        ...here goes some more...
        self.initUI2()

, main2()

+5
1

QApplication .

, GUI , , app.exec(), , app.exec() .

QApplication - Qt. Qt-, , ++.

, , :

def main():
    app = QtGui.QApplication(sys.argv)

    ex = QtGui.QWidget()
    ex.show()
    ex2 = QtGui.QWidget()
    ex2.show()

    sys.exit(app.exec())
+6

All Articles