Frames and Dialogs → Aui_MDI
# Demo: wxAuiMDIParentFrame.py
# Desp: In wxPython, wx.aui package supplies Advanced User Interface.
# It can lead to Simple but Rich UI.
import wx
import wx.aui
class MDIParentFrame(wx.aui.AuiMDIParentFrame):
def __init__(self, parent):
wx.aui.AuiMDIParentFrame.__init__(self, parent, -1,
title="Test AuiMDIParentFrame",
size=(640, 480),
style=wx.DEFAULT_FRAME_STYLE)
# Total count of child frames that have been newed
self.CountOfChildFrame = 0
MenuBar = self.MakeMenuBar()
self.SetMenuBar(MenuBar)
self.CreateStatusBar()
def MakeMenuBar(self):
MenuBar = wx.MenuBar()
FileMenu = wx.Menu()
MenuItem = FileMenu.Append(-1, "New Child Window\tCtrl-N")
self.Bind(wx.EVT_MENU, self.OnNewChildWindow, MenuItem)
MenuItem = FileMenu.Append(-1, "Close Parent")
self.Bind(wx.EVT_MENU, self.OnClose, MenuItem)
MenuBar.Append(FileMenu, "&File")
return MenuBar
def OnNewChildWindow(self, event):
self.CountOfChildFrame += 1
ChildFrame = MDIChildFrame(self, self.CountOfChildFrame)
ChildFrame.Show(True)
def OnClose(self, event):
self.Close(True)
class MDIChildFrame(wx.aui.AuiMDIChildFrame):
def __init__(self, parent, index):
wx.aui.AuiMDIChildFrame.__init__(self, parent, -1,
title="Child %d" % index)
# Childs can custom their own menubar
MenuBar = parent.MakeMenuBar()
ChildMenu = wx.Menu()
MenuItem = ChildMenu.Append(-1, "This is child %d's menu" % index)
MenuBar.Append(ChildMenu, "&Child")
self.SetMenuBar(MenuBar)
Panel = wx.Panel(self)
wx.StaticText(Panel, -1, "This is child %d " % index, (10, 10))
Panel.SetBackgroundColour("light blue")
Sizer = wx.BoxSizer()
Sizer.Add(Panel, 1, wx.EXPAND)
self.SetSizer(Sizer)
wx.CallAfter(self.Layout)
def TestMDIParentFrame():
TheApp = wx.PySimpleApp()
ParentFrame = MDIParentFrame(None)
ParentFrame.Show(True)
TheApp.MainLoop()
if __name__ == "__main__":
TestMDIParentFrame()