Microsoft's Multiple Document Interface, or MDI, allows a parent window to house multiple child windows. The wxPython library supports the Multiple Document Interface, and it is simple to include it in your applications: from wxPython.wx import * # Subclass wxMDIParentFrame class Parent ( wxMDIParentFrame ): def __init__ ( self ): # Call __init__ and make the window big wxMDIParentFrame.__init__ ( self, None, -1, "Multiple Document Interface Test", size = ( 500, 500 ) ) # Create a menu that allows us to open new windows windowMenu = wxMenu() windowMenu.Append ( 1, 'Open New' ) # Create a menu bar and add the menu menuBar = wxMenuBar() menuBar.Append ( windowMenu, 'Options' ) self.SetMenuBar ( menuBar ) # Catch a menu click EVT_MENU ( self, 1, self.openNew ) self.Show ( True ) # This method will add a window def openNew ( self, event ): # Create a child window child = wxMDIChildFrame ( self, -1, 'MDI Child' ) # Give the child a panel child.panel = wxPanel ( child, -1 ) child.panel.SetSize ( child.GetClientSize() ) # Add a label child.label = wxStaticText ( child, -1, 'I am only a child.' ) child.Show ( True ) application = wxPySimpleApp() Parent() application.MainLoop() Although the idea sounds complicated at first, wxPython makes it all extremely easy, requiring only a handful of code to create something basic like we did. Notice, too, that a “Window” menu is added to our application, giving us organization and navigation options. The Multiple Document Interface is useful in some applications. Each window has the potential to be very different from the next window, too. It's all up to your creativity. Conclusion The wxPython library offers more frames than just wxFrame. These frames are geared toward specific things, such as modal dialogs, modeless dialogs, wizards and organizing child windows within a large parent window. They enable you to extend your application's capabilities with little effort, and, at the same time, give you a variety of complex options. They can be excellent additions to your applications, benefitting the end user and, in turn, you –- the developer.
blog comments powered by Disqus |
|
|
|
|
|
|
|