How does wxpython exit Mainloop?

只谈情不闲聊 提交于 2020-01-04 20:48:50

问题


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()
  • When "exit" is clicked, what happens exactly?
  • When "exit" is clicked, what happens to app.MainLoop()?
  • Is clicking "X" button on top-right of the frame window same with clicking "exit" button?
  • 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?
  • Why wouldn't it print "ok" when I click "exit" if I run the script this way:

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

  2. 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.

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

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

  4. 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.

  5. 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.



来源:https://stackoverflow.com/questions/20659683/how-does-wxpython-exit-mainloop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!