How to keep the window created by open PyQT5?

1

After a long study of the object orientation part, I started to study PyQT5. I was doubtful in the following code:

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.title='Hello, world!'
        self.left=10
        self.top=10
        self.width=640
        self.height=480
        self.initUI()
    def initUI(self):
            self.setWindowTitle(self.title)
            self.setGeometry(self.left,self.top,self.width,self.height)
            self.show()
if __name__=='__main__':
    app=QApplication(sys.argv)
    ex=App()

In this code the window that was to be generated is less than a second on the screen and already disappears when I squeeze the code in PyCharm. In Python 3.7 IDE it runs normal. How do I fix this?

    
asked by anonymous 26.12.2018 / 10:57

1 answer

1

is missing the program output, add sys.exit(app.exec_()) , like this:

if __name__=='__main__':
    app=QApplication(sys.argv)
    ex=App()
    sys.exit(app.exec_())
    
26.12.2018 / 11:33