Wxpython 如何删除AuiNotebook的页面?

Wxpython 如何删除AuiNotebook的页面?,wxpython,Wxpython,我使用AuiNotebook创建了frame,并重新定义了EVT_AuiNotebook_PAGE_CLOSE事件,其中调用了DeletePage: def OnAuiNotebookPageClose( self, event ): auinotebook = event.GetEventObject() page_idx = event.GetSelection() auinotebook.DeletePage(page_idx) 单击页面上的“X”按钮将调用事件,

我使用AuiNotebook创建了frame,并重新定义了EVT_AuiNotebook_PAGE_CLOSE事件,其中调用了DeletePage:

def OnAuiNotebookPageClose( self, event ):
    auinotebook = event.GetEventObject()
    page_idx = event.GetSelection()
    auinotebook.DeletePage(page_idx)
单击页面上的“X”按钮将调用事件,但DeletePage始终返回False,页面未被删除。。。我的代码有什么问题

请看下面我的代码

import wx
import wx.xrc
import wx.aui

class Frame1 ( wx.Frame ):

    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

        self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )

        bSizer1 = wx.BoxSizer( wx.VERTICAL )

        self.m_auinotebook1 = wx.aui.AuiNotebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.aui.AUI_NB_DEFAULT_STYLE )
        self.m_panel2 = wx.Panel( self.m_auinotebook1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        self.m_auinotebook1.AddPage( self.m_panel2, u"page1", True, wx.NullBitmap )
        self.m_panel3 = wx.Panel( self.m_auinotebook1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        self.m_auinotebook1.AddPage( self.m_panel3, u"page2", False, wx.NullBitmap )
        self.m_panel4 = wx.Panel( self.m_auinotebook1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        self.m_auinotebook1.AddPage( self.m_panel4, u"page3", False, wx.NullBitmap )

        bSizer1.Add( self.m_auinotebook1, 1, wx.EXPAND |wx.ALL, 5 )


        self.SetSizer( bSizer1 )
        self.Layout()

        self.Centre( wx.BOTH )

        # Connect Events
        self.m_auinotebook1.Bind( wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnAuiNotebookPageClose )

    def OnAuiNotebookPageClose( self, event ):
        auinotebook = event.GetEventObject()
        page_idx = event.GetSelection()
        auinotebook.DeletePage(page_idx)


if __name__ == "__main__":
    app = wx.App(False)
    frame = Frame1(None)
    frame.CenterOnScreen()
    frame.Show(True)
    app.MainLoop()

将事件绑定到
EVT\u AUINOTEBOOK\u PAGE\u CLOSE
EVT\u AUINOTEBOOK\u PAGE\u CLOSE

使用
RemovePage
然后使用
DeletePage

i、 e:

    self.m_auinotebook1.Bind( wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED, self.OnAuiNotebookPageClose )

def OnAuiNotebookPageClose( self, event ):
    auinotebook = event.GetEventObject()
    page_idx = event.GetSelection()
    auinotebook.RemovePage(page_idx)
    auinotebook.DeletePage(page_idx)