简体   繁体   中英

wxpython get currently selected notebook tab label (not index)

I have an EVT_NOTEBOOK_PAGE_CHANGED function to alert me when the tab changes, but I can only get it to tell me the index of the notebook tab:

self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.eventntbkParameters, self.ntbkParameters)

&

page = self.ntbk.GetSelection()
print page

I don't think this it is very safe to determine the which tab is selected in this way in case an extra tab is added in the future, reshuffling the indices. Is it possible to get the label of the tab instead?

Thank you

You want ntbk.GetPageText(evt.GetSelection()) .

class MyNotebook(AuiNotebook):
  def __init__(self, parent, id, *args, **kwds): #@ReservedAssignment
    AuiNotebook.__init__(self, parent, id, *args,
      style = NO_BORDER | AUI_NB_CLOSE_ON_ALL_TABS | AUI_NB_TAB_SPLIT, **kwds)

    self._tabs = ['Jobs', 'Devices', 'Actions', 'Transforms']

    self.Bind(EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnPageClosed)

  def OnPageClosed(self, evt):
    page = self.GetPageText(evt.GetSelection())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM