wxpython 如何退出Mainloop? [英] How does wxpython exit Mainloop?

查看:87
本文介绍了wxpython 如何退出Mainloop?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 wxpython 应用程序,它以这种方式运行:

I have a wxpython application, it runs this way:

if __name__ == "__main__":
    app = wx.App(False)
    frame = MainWindow("Application")
    frame.Show()
    app.MainLoop()

应用程序的菜单栏上有一个退出"菜单项,它绑定:

there is an "exit" menu item on the application's menu bar, which binds:

def onExit(self, event):
    """"""
    self.Close()

  • 点击退出"后,究竟会发生什么?
  • 当点击退出"时,app.MainLoop() 会发生什么?
  • 是否单击框架窗口右上角的X"按钮点击退出"按钮?
  • 为什么当我单击X"按钮时 python.exe*32 进程没有结束,并且当我单击X"按钮时,如何终止 python.exe*32 进程?
  • 如果我运行脚本,当我点击退出"时为什么不打印 "ok"这样:

    if __name__ == "__main__":
        app = wx.App(False)
        frame = MainWindow("Application")
        frame.Show()
        app.MainLoop()
        print "ok"
    

  • 推荐答案

    1. 当点击退出"时,究竟发生了什么?

    1. When "exit" is clicked, what happens exactly?

    'exit' 有一个事件绑定来调用 onExit 方法,该方法调用 MainWindow 的这个实例的 close 方法.这会调用一个 EVT_CLOSE 事件,您可以选择绑定到它并控制发生的事情,如果您不绑定,它会调用 Destroy 方法来安全地销毁窗口.

    'exit' has an event binding to call the method onExit which calls the close method of this instance of MainWindow. This invokes an EVT_CLOSE event, you have the option to bind to this and control what happens, if you dont bind, it calls the Destroy method which destroys the window safely.

    当点击退出"时,app.MainLoop() 会发生什么?

    When "exit" is clicked, what happens to app.MainLoop()?

    除非最后一个顶级窗口关闭,否则主循环将继续处理事件,当发生这种情况时,主循环结束.

    The mainloop will continue processeing events unless the last of its top level windows is closed, when this happens the mainlop ends.

    点击框架窗口右上角的X"按钮和点击退出"按钮一样吗?

    Is clicking "X" button on top-right of the frame window same with clicking "exit" button?

    它与生成 EVT_CLOSE 事件相同,该事件与上述 onExit 绑定.​​

    Its kind of the same as it generates a EVT_CLOSE event which has a binding to onExit as above.

    为什么当我点击X"按钮时python.exe*32进程没有结束,我如何在我点击X"按钮时杀死python.exe*32进程?

    Why doesn't python.exe*32 process end when I click "X" button, and how do I kill python.exe*32 process end when I click "X" button?

    它应该在所有顶级窗口都关闭时结束,您必须仍然存在一个顶级窗口.

    It should end when all top level windows are closed, you must still have a top level window in existance.

    如果我以这种方式运行脚本,为什么当我点击退出"时它不会打印ok"

    Why wouldn't it print "ok" when I click "exit" if I run the script this way

    通常情况下,当没有剩余的顶级窗口时.

    Normally it would when there are no top level windows left.

    这篇关于wxpython 如何退出Mainloop?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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