2013-10-04 144 views
0

無論何時切換標籤頁,我都想獲取下列代碼的活動標籤索引。有沒有內置函數?如何獲取wxnotebook中活動選項卡的選項卡號?

import wx 

創建筆記本:

class PageOne(wx.Panel): 
def __init__(self, parent): 
    wx.Panel.__init__(self, parent) 
    t = wx.StaticText(self, -1, "Histogram Plot", (20,20)) 
    self.currentTab=1 


class PageTwo(wx.Panel): 
def __init__(self, parent): 
    wx.Panel.__init__(self, parent) 
    t = wx.StaticText(self, -1, "This is a PageTwo object", (40,40)) 
    self.currentTab=2 


class PageThree(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent) 
     t = wx.StaticText(self, -1, "This is a PageThree object", (60,60)) 
     self.currentTab=3 


class MainFrame(wx.Frame): 
    def __init__(self): 
    wx.Frame.__init__(self, None, title="Plots") 

    # Here we create a panel and a notebook on the panel 
    p = wx.Panel(self) 
    nb = wx.Notebook(p) 

    # create the page windows as children of the notebook 
    page1 = PageOne(nb) 
    page2 = PageTwo(nb) 
    page3 = PageThree(nb) 

    # add the pages to the notebook with the label to show on the tab 
    nb.AddPage(page1, "Plot 1") 
    nb.AddPage(page2, "Plot 2") 
    nb.AddPage(page3, "Plot 3") 

    # finally, put the notebook in a sizer for the panel to manage 
    # the layout 
    sizer = wx.BoxSizer() 
    sizer.Add(nb, 1, wx.EXPAND) 
    p.SetSizer(sizer) 

# bind event to notebook 
    nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.ChangingTest) 

def ChangingTest(self, evt): 
    print "It worked!" 

嘗試GetSelection()和印刷currentTab,但沒有發現任何運氣那裏。謝謝。

回答

0

看看wxPython演示,看起來你需要event.GetSelection()或者可能self.GetSelection,其中「self」指的是Notebook。演示示例綁定的事件是EVT_NOTEBOOK_PAGE_CHANGED。

+0

我試過那個麥克,但它顯示屬性錯誤:'主框架對象沒有屬性'GetSelection' – mvsrs

+0

請注意,我說「自我」是指筆記本。所以它會像「self.myNotebook.GetSelection()」 –

相關問題