How do I create and use an application object

Every wxPython application needs exactly one application object. The application object must be an instance of the class wx.App, or a custom subclass thereof. The primary purpose of the application object is to manage the main event loop behind the scenes. This event loop responds to windowing system events and dispatches them to the appropriate event handler. The application object is so important to the management of a wxPython process that you cannot create any wxPython graphical objects until after your program has instantiated an application object.

The parent wx.App class also defines a few properties which are global to the entire application. Much of the time, that's all the functionality you'll need from your application object. A custom application subclass can be used if you need to manage other global data or connections (such as a database connection). In some cases, you might also want to extend the main event loop for more specialized error or event handling. However, the default event loop will be suitable for nearly all wxPython applications that you will write.

Was this article helpful?

0 0

Post a comment