我使用AuiNotebook创建了框架,并重新定义了称为DeletePage的EVT_AUINOTEBOOK_PAGE_CLOSE事件:
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()
答案 0 :(得分:0)
将事件绑定到EVT_AUINOTEBOOK_PAGE_CLOSED
而不是EVT_AUINOTEBOOK_PAGE_CLOSE
使用RemovePage
,然后使用DeletePage
即:
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)