【问题标题】:How can I get tab number of active tab in wxnotebook?如何获取 wxnotebook 中活动选项卡的选项卡编号?
【发布时间】:2013-10-04 11:42:14
【问题描述】:

每当切换选项卡时,我想获取以下代码的活动选项卡索引。有内置功能吗?

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,但没有找到任何运气。谢谢。

【问题讨论】:

    标签: python wxpython


    【解决方案1】:

    查看 wxPython 演示,您似乎需要 event.GetSelection() 或可能 self.GetSelection,其中“self”指的是 Notebook。演示示例绑定的事件是 EVT_NOTEBOOK_PAGE_CHANGED。

    【讨论】:

    • 我试过那个麦克,但它显示属性错误:'主框架对象没有属性'GetSelection'
    • 请注意,我说的“self”是指笔记本。所以它会像“self.myNotebook.GetSelection()”
    猜你喜欢
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 2022-08-05
    相关资源
    最近更新 更多