如何删除AuiNotebook的页面? [英] How to delete page of AuiNotebook?

查看:28
本文介绍了如何删除AuiNotebook的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 AuiNotebook 创建了框架并重新定义了调用 DeletePage 的 EVT_AUINOTEBOOK_PAGE_CLOSE 事件:

I created frame with AuiNotebook and redefine EVT_AUINOTEBOOK_PAGE_CLOSE event where DeletePage is called:

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

点击页面上的X"按钮,事件被调用,但DeletePage总是返回False,页面没有被删除......我的代码有什么问题?

On click the "X" button on the page the event is invoked, but DeletePage always returned False, page was not removed... What is wrong in my code?

请看下面我的代码.

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_AUINOTEBOOK_PAGE_CLOSED 不是 EVT_AUINOTEBOOK_PAGE_CLOSE
使用 RemovePage 然后 DeletePage
即:

Bind the event to EVT_AUINOTEBOOK_PAGE_CLOSED Not EVT_AUINOTEBOOK_PAGE_CLOSE
Use RemovePage then 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)

这篇关于如何删除AuiNotebook的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆