python - PyQt Window construction -


Can someone tell me the difference between the following two code examples? Why the top is not working? It executes without error, but the window does not remain open. Importing QtGui from PyQt4 import SYS app = QtGui.QApplication (sys.argv) QtGui.QMainWindow (). Show () ap .exec_ ()

And: QtGui import from the PyQt4 import SYS app = QtGui.QApplication (sys.argv) win = QtGui.QMainWindow () Win.show () app .exec_ ()

in QtGui.QMainWindow (). Show () You are creating an object of QMainWindow and you are showing it but if you do not save that example of QMainWindow in your memory Eventually the drone collection of the dragon removes that example and your QMainWindow does not show anymore

in the second code: win = QtGui.QMainWindow () You can save the object object from QMainWindow to win your memory. Python does not consider it as garbage because it is in use and therefore your window remains open

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -