Search code examples
pythonwxpythonwxwidgets

WxWidgets: do I need to run MainLoop when using only modals?


I'm using wxWdigets (wxPython to be exact) to display some modal dialogs.

This page https://wxpython.org/Phoenix/docs/html/wx.EventLoopBase.html says:

Temporary event loops are usually created by wx.Dialog.ShowModal .

So while I still need to create the wx.App object to initialize the window system, my understanding is that if I only use modal dialogs then I don't need to call the MainLoop on the wx.App object.

In practice not calling MainLoop seems to work fine - however I wasn't able to find a definitive answer in the wx Documentation.

My specific worry is that MainLoop might be doing some cleanup when it exits, which I would be missing by not invoking it.

So my question: is it necessary to call MainLoop when using only modals?


Solution

  • No, you don't need to run the main event loop if you only need to show a modal dialog. However you still need to initialize the library, which is typically done by creating the wxApp object, so you still have to do this.