GUI window in Python (PyQT) flashing and closing down immediately?

smilingbuddha

I am new to PyQT and I have just started learning about it through this video: https://www.youtube.com/watch?v=JBME1ZyHiP8

When I ran the code on my Ubuntu 14.04

import sys
from PyQt4 import QtGui # Always have these two imports

app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()
window.setGeometry(50,50,500,300)
window.setWindowTitle("PyQt start")

window.show()

The window crated just flashes and closes down. How do I get the window to stay so that I can interact with it? The code in the Youtube video above demonstrated it on a Windows platform. Do I have to append anything Ubuntu specific to my code?

101

You aren't running the app, add this line to the end:

sys.exit(app.exec_())

From the relevant documentation:

int QApplication.exec_ ()

Enters the main event loop and waits until exit() is called, then returns the value that was set to exit() (which is 0 if exit() is called via quit()).

It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.

Generally, no user interaction can take place before calling exec(). As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widgets call exec() to start a local event loop.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Window is closing immediately after I run program in PyQt 4 (anaconda) [PyCharm 4.5]

From Dev

Python Kernel crashes after closing an PyQt4 Gui Application

From Dev

PyQt QWidget window closes immediately upon showing?

From Dev

Closing the GUI window does not end the program

From Dev

Closing a GUI window from the command line

From Dev

Python 3 | Closing Window on Tkinter

From Dev

How do I execute more code after closing a PyQt window?

From Dev

How to close serial port when closing window with pyqt5

From Dev

How to detect if window is flashing

From Dev

Flashing window in gnu screen

From Dev

How to prevent Spring Boot daemon/server application from closing/shutting down immediately?

From Dev

Inno Setup: Combo box closing immediately on drop-down (which starts an application)

From Dev

MySQL Reader closing immediately

From Dev

Python tkinter mainloop not quitting on closing the window

From Dev

Python GTK 3+ controlling closing the window

From Dev

close sub-window without closing main window PyGTK in python

From Dev

Closing main window from toplevel window with tkinter in python

From Dev

Python PyQT4 Simple database GUI

From Dev

Python PyQt separate backend from GUI

From Dev

crazy flashing window OpenGL GLFW

From Dev

Update a dialog without closing it immediately?

From Dev

My main form is closing immediately

From Dev

Interop word processes not closing immediately

From Dev

Interop word processes not closing immediately

From Dev

python pyqt wider window than screen width

From Dev

How do I switch layouts in a window using PyQt?? (Without closing/opening windows)

From Dev

[PyQt]Open second window every time i push the button without closing the program

From Dev

Python output window disappears immediately in eclipse after run

From Dev

fadeIn fadeOut flashing upon scroll up and down

Related Related

  1. 1

    Window is closing immediately after I run program in PyQt 4 (anaconda) [PyCharm 4.5]

  2. 2

    Python Kernel crashes after closing an PyQt4 Gui Application

  3. 3

    PyQt QWidget window closes immediately upon showing?

  4. 4

    Closing the GUI window does not end the program

  5. 5

    Closing a GUI window from the command line

  6. 6

    Python 3 | Closing Window on Tkinter

  7. 7

    How do I execute more code after closing a PyQt window?

  8. 8

    How to close serial port when closing window with pyqt5

  9. 9

    How to detect if window is flashing

  10. 10

    Flashing window in gnu screen

  11. 11

    How to prevent Spring Boot daemon/server application from closing/shutting down immediately?

  12. 12

    Inno Setup: Combo box closing immediately on drop-down (which starts an application)

  13. 13

    MySQL Reader closing immediately

  14. 14

    Python tkinter mainloop not quitting on closing the window

  15. 15

    Python GTK 3+ controlling closing the window

  16. 16

    close sub-window without closing main window PyGTK in python

  17. 17

    Closing main window from toplevel window with tkinter in python

  18. 18

    Python PyQT4 Simple database GUI

  19. 19

    Python PyQt separate backend from GUI

  20. 20

    crazy flashing window OpenGL GLFW

  21. 21

    Update a dialog without closing it immediately?

  22. 22

    My main form is closing immediately

  23. 23

    Interop word processes not closing immediately

  24. 24

    Interop word processes not closing immediately

  25. 25

    python pyqt wider window than screen width

  26. 26

    How do I switch layouts in a window using PyQt?? (Without closing/opening windows)

  27. 27

    [PyQt]Open second window every time i push the button without closing the program

  28. 28

    Python output window disappears immediately in eclipse after run

  29. 29

    fadeIn fadeOut flashing upon scroll up and down

HotTag

Archive