我的应用程序由一个MDIParentFrame组成,它尝试打开两个MDIChildFrame。 我说“尝试”因为每次打开第一个MDIChildFrame时,我的MDIParentFrame会在菜单栏中显示由MDIChildFrame导出的菜单,并且永远不会恢复自己的菜单。
我不知道如何停用我的MDIChildFrame,以便MDIPArentFrame再次显示自己的菜单,以便通过其菜单加载第二个MDIChildFrame。
这是我的代码:
import wx
class MDIFrame(wx.MDIParentFrame):
def __init__(self):
wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent",size=(600,400))
menu = wx.Menu()
menu.Append(5000, "&New Window 1")
menu.Append(5002, "&New Window 2")
menu.Append(5001, "E&xit")
menubar = wx.MenuBar()
menubar.Append(menu, "&File")
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.OnNewWindow1, id=5000)
self.Bind(wx.EVT_MENU, self.OnExit, id=5001)
self.Bind(wx.EVT_MENU, self.OnNewWindow2, id=5002)
def OnExit(self, evt):
self.Close(True)
def OnNewWindow1(self, evt):
#win = wx.MDIChildFrame(self, -1, "Child Window")
win = MDIHijo1(self)
win.Show(True)
def OnNewWindow2(self, evt):
#win = wx.MDIChildFrame(self, -1, "Child Window")
win = MDIHijo2(self)
win.Show(True)
class MDIHijo1(wx.MDIChildFrame):
def __init__(self,parent):
wx.MDIChildFrame.__init__(self,parent,title='Ventana Hijo 1')
menu = wx.Menu()
menu.Append(5500, "&Son 1")
menu.Append(5501, "&Son 1")
menubar = wx.MenuBar()
menubar.Append(menu, "&File")
self.SetMenuBar(menubar)
class MDIHijo2(wx.MDIChildFrame):
def __init__(self,parent):
wx.MDIChildFrame.__init__(self,parent,title='Ventana Hijo 2')
menu = wx.Menu()
menu.Append(5500, "&Son 2")
menu.Append(5501, "&Son 2")
menubar = wx.MenuBar()
menubar.Append(menu, "&File")
self.SetMenuBar(menubar)
app = wx.PySimpleApp()
frame = MDIFrame()
frame.Show()
app.MainLoop()
非常感谢你的帮助, 最好的祝福, 哈维尔。
答案 0 :(得分:0)
您想将新菜单项“Son 1”/“Son 2”添加到菜单“Window”吗?
您可以使用menu = parent.GetWindowMenu()并将菜单项追加到它。
import wx
class MDIFrame(wx.MDIParentFrame):
def __init__(self):
wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent",size=(600,400))
menu = wx.Menu()
menu.Append(5000, "&New Window 1")
menu.Append(5002, "&New Window 2")
menu.Append(5001, "E&xit")
menubar = wx.MenuBar()
menubar.Append(menu, "&File")
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.OnNewWindow1, id=5000)
self.Bind(wx.EVT_MENU, self.OnExit, id=5001)
self.Bind(wx.EVT_MENU, self.OnNewWindow2, id=5002)
def OnExit(self, evt):
self.Close(True)
def OnNewWindow1(self, evt):
#win = wx.MDIChildFrame(self, -1, "Child Window")
win = MDIHijo1(self)
win.Show(True)
def OnNewWindow2(self, evt):
#win = wx.MDIChildFrame(self, -1, "Child Window")
win = MDIHijo2(self)
win.Show(True)
class MDIHijo1(wx.MDIChildFrame):
def __init__(self,parent):
wx.MDIChildFrame.__init__(self,parent,title='Ventana Hijo 1')
menu = parent.GetWindowMenu()
menu.Append(5500, "&Son 1")
menu.Append(5501, "&Son 1")
# menubar = wx.MenuBar()
# menubar.Append(menu, "&File")
# self.SetMenuBar(menubar)
class MDIHijo2(wx.MDIChildFrame):
def __init__(self,parent):
wx.MDIChildFrame.__init__(self,parent,title='Ventana Hijo 2')
menu = parent.GetWindowMenu()
menu.Append(5500, "&Son 2")
menu.Append(5501, "&Son 2")
# menubar = wx.MenuBar()
# menubar.Append(menu, "&File")
# self.SetMenuBar(menubar)
app = wx.PySimpleApp()
frame = MDIFrame()
frame.Show()
app.MainLoop()