如何在 wxnotebook 中获取活动选项卡的选项卡编号? [英] How can I get tab number of active tab in wxnotebook?

查看:46
本文介绍了如何在 wxnotebook 中获取活动选项卡的选项卡编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在切换选项卡时获取以下代码的活动选项卡索引.有没有内置函数?

I want to get the active tab index for the following code whenever tab is switched. Is there any built in function?

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

Tried GetSelection() and printing currentTab but did not find any luck there. Thanks.

推荐答案

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

Looking at the wxPython demo, it appears that you want event.GetSelection() or possibly self.GetSelection where "self" refers to the Notebook. The event that the demo example is bound to is EVT_NOTEBOOK_PAGE_CHANGED.

这篇关于如何在 wxnotebook 中获取活动选项卡的选项卡编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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