How to keep the window created by Pyqt5 open?

Asked

Viewed 110 times

1

After studying the object orientation part for a long time 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 q was to be generated gets less than a second on the screen and already disappears when I run the code in Pycharm. In Python IDE 3.7 it runs normal. How do I fix this?

1 answer

1


is missing from the program, add the sys.exit(app.exec_()), thus:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.