Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does wxpython exit Mainloop?

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"
    
like image 863
alwbtc Avatar asked Oct 16 '25 00:10

alwbtc


1 Answers

  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.

like image 187
Yoriz Avatar answered Oct 17 '25 14:10

Yoriz