How do I create and use the toplevel window object

A top-level window object is a widget (usually a frame) that is not contained by another widget in your application—it's what a typical user would point to and say, "That's the program." The top-level window object is usually the main window of your application and contains widgets and interface objects that the user interacts with. As we have seen, the application exits when all top-level windows are closed.

Your application must have at least one top-level window object. The top-level window object is usually a subclass of the class wx.Frame, although it can also be a subclass of wx.Dialog. Most of the time, you will define custom subclasses of wx.Frame for use in your application. However, there are a number of pre-defined wx.Dialog subclasses that provide many of the typical dialogs that you might encounter in an application.

There's some naming confusion here, due to overloading of the word top. A generic "top-level" window is any widget in your application that doesn't have a parent container. Your application must have at least one of these, but it can have as many as you'd like. Only one of these windows, however, can be explicitly blessed by wxPython as the main top window by using SetTopWindow(). If you do not specify a main window with SetTopWindow, then the first frame in the wx.App's top-level window list is considered to be the top window. So, explicitly specifying the top window is not always necessary—you don't need to if, for example, you only have one top window. Repeated calls to SetTopWindow() will replace the current top window—an application can only have one top window at a time.

Was this article helpful?

0 0

Responses

  • Peter
    What is the top level window in wxpython?
    8 months ago

Post a comment