为什么app和widget之间没有引用? [英] why is there no reference between the app and the widget?

查看:180
本文介绍了为什么app和widget之间没有引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是
为何的后续行动应用程序会在sys.exit命令后显示吗?

我正在学习本教程:

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

我稍微修改了代码来测试东西

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_())

我很困惑为什么没有 app 和 w 我希望某种迹象表明 w 是一个孩子或者 app

I'm 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.

推荐答案

对于使用Qt的任何GUI应用程序,无论应用程序在任何给定时间是否具有0,1,2或更多窗口,都只有一个QApplication对象。所有窗口都由应用程序自动管理。

For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any given time. All windows are automatically managed by the Application.

您必须初始化它并将其保存到 exec 它虽然。

You do have to initialize it and to get a hold of it to exec it though.

您必须在任何其他GUI对象之前创建应用程序(因为它们由它管理)。

You must create the Application before any other GUI objects (because they are managed by it).

QApplication对象的详细说明

这篇关于为什么app和widget之间没有引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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