Summary

■ The foundation of a wxPython program is based on two required objects: an application object and the top-level window. Every wxPython application needs to instantiate one instance of wx.App, and have at least one toplevel window.

■ The application object contains the wx.App.Onlnit() method, which is called on startup. This method is the preferred place to initialize frames and other global objects. A wxPython application normally shuts down when all of its top-level windows have closed, or when the main event loop is otherwise exited.

■ The application object also controls where wxPython directs textual output. By default, wxPython redirects stdout and stderr to a special window. This behavior can make it hard to troubleshoot startup errors. Luckily, it's no trouble at all to change this behavior to allow wxPython to send error messages to a file or console window.

■ A wxPython application usually has at least one subclass of wx.Frame. A wx.Frame object can be created in multiple styles using the style parameter. Every wxWidgets object, including frames, has an ID, which can be explicitly assigned by the application or generated by wxPython. Subwindows are the meat of a frame, inserted into a frame by creating the subwindow with that frame as a parent. Usually, a frame contains a single wx.Panel and further subwindows are placed in the panel. A frame's single subwindow is automatically resized when the parent frame resizes. Frames have explicit mechanisms for managing a menubar, toolbar, and status bar.

■ Although you'll use frames for anything complex, when you want to simply get quick information from a user, you can show the user a standard dialog window. There are standard dialogs for many tasks, including an alert box, simple text entry, and entry from a list.

Now that we've talked about the foundation of a wxPython program in terms of the required data objects, we'll start to talk about the basic blocks of a wxPython program as it manages the flow of control while running. In the next chapter, we'll talk about events and the event loop.

Was this article helpful?

0 0

Post a comment