Search code examples
pythonwxpythonwxwidgets

purpose of wx.App when just showing a frame is enough


What is the use of the wx.App class (apart from what the documentation says), when you can just create a frame and .Show(True) it?

When should a wx.App class be used, or why shouldn't you create a frame and just show it?


Solution

  • You have to create a wx.App. If you try to instantiate wxPython classes before creating the app, it will fail:

    >>> import wx
    >>> frame = wx.Frame(None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 505, in __init__
        _windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))
    wx._core.PyNoAppError: The wx.App object must be created first!
    

    There will always be one, and only one, wx.App. Instantiating it initializes wxPython - creates the window thread, etc.