- 论坛徽章:
- 3
|
本帖最后由 ipx-spx 于 2014-08-11 16:54 编辑
#!C:\Python27\python
# -*- coding:utf-8 -*-
import wx
class MyFrame(wx.MDIParentFrame):
def __init__(self):
wx.MDIParentFrame.__init__(self, None, wx.NewId(), "Test NoteBook")
menuBar = wx.MenuBar()
menuFile = wx.Menu()
menuBar.Append(menuFile, "File")
newFile = menuFile.Append(wx.NewId(), "New")
menuFile.AppendSeparator()
self.Bind(wx.EVT_MENU, self.newFrame, newFile)
exitFile = menuFile.Append(wx.NewId(), "Exit")
self.Bind(wx.EVT_MENU, self.closeMe, exitFile)
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_CLOSE, self.closeMe)
def newFrame(self, evt):
mpf = MyParentFrame(self)
mpf.Show()
def closeMe(self, evt):
self.Destroy()
class MyParentFrame(wx.MDIChildFrame):
def __init__(self, parent):
wx.MDIChildFrame.__init__(self, parent, wx.NewId())
p = wx.Panel(self)
mnb = MyNotebook(p)
mnb.Show()
bs = wx.BoxSizer(wx.VERTICAL)
bs.Add(mnb, 1, wx.EXPAND)
p.SetSizer(bs)
class MyNotebook(wx.Notebook):
def __init__(self, parent):
self.parent = parent
wx.Notebook.__init__(self, parent, wx.NewId())
self.page1 = MyPage1(self)
self.page2 = MyPage2(self)
self.AddPage(self.page1, "One")
self.AddPage(self.page2, "Two")
class MyPage1(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.NewId())
self.parent = parent
st = wx.StaticText(self, wx.NewId(), "Page A")
btn = wx.Button(self, wx.NewId(), "Quit")
self.Bind(wx.EVT_BUTTON, self.closeMe, btn)
bs = wx.BoxSizer(wx.VERTICAL)
bs.Add(st, 0, 0)
bs.Add(btn, 0, 0)
self.SetSizer(bs)
def closeMe(self, evt):
MyParentFrame.closeMe(self.parent.parent)
class MyPage2(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.NewId())
st = wx.StaticText(self, wx.NewId(), "Page B")
if __name__ == "__main__":
app = wx.App()
frame = MyFrame()
frame.Show()
app.MainLoop()
我想用wx.Notebook的page中的一个按钮关闭子框架,留下父框架,但是红色部分的代码是错误的,因为wx.Notebook无法关闭子框架,请教各位大大,如何实现? |
|