为什么应用程序会在sys.exit命令之后显示? [英] why will the application show after sys.exit command?

查看:145
本文介绍了为什么应用程序会在sys.exit命令之后显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注本教程:

http://zetcode.com/tutorials/pyqt4/firstprograms/

在第一个例子中我不明白为什么应用程序显示只有在命令之后:

and on the very first example I don't understand why does the application show only after the command:

sys.exit(app.exec_())

此外,我稍微修改了代码以测试事物

Also, I modified the code slightly to test things

import sys
from PyQt4 import QtGui


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    w = QtGui.QWidget()
    w.resize(250,150)
    w.move(300,300)
    w.setWindowTitle("Title")
    w.show()
    sys.exit(app.exec_())

如果我在终端运行并注释掉最后一行只会在运行最后一行后显示窗口。

If I run this in the terminal and comment out the last line it will only show the window after running the last line.

我不太明白最后一行是做什么的。

I don't quite understand what the last line does.

EDI T:

我也很困惑为什么没有 app 和<$ c的引用$ c> w 我希望某种迹象 w 是一个孩子或 app

I'm also confused as to why there isn't a reference of app and w i'd expect some kind of indication that w is a child or something of app.

我在Spyder和一个IPython解释器中运行它。

I'm running it in Spyder and an IPython interpreter.

推荐答案

相当于

status = app.exec_()   # run app, show window, wait for input
sys.exit(status)       # terminate program with a status code returned from app

这篇关于为什么应用程序会在sys.exit命令之后显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆