3

I'm experimenting with wxPython,

I have a tabbed interface (notebook) and each tab is basically a file list view (yes, I'm trying to make a file manager)

The file list inherits from wx.ListCtrl, and the tabbed interface inherits from wx.Notebook

I'm just starting .. and I had it so double clicking on a folder will cd into that folder, but I want to also change the title of the tab.

How do I do that?

I have the object that represents the file list and the title I want to set it to,

[ EDIT Notebook.SetPageText() takes a number, so I can't pass the tab object directly to it ]

my current approach is to cycle through the tabs until one of them matches my tab:

    for tab_id in range(self.GetPageCount()):
        if self.GetPage(tab_id) == tab:
            self.SetPageText(tab_id, title)
            break

This seems rather naive though, isn't there a smarter approach?

4

3 回答 3

2

我不知道 wxPython,但我认为它包装了 C++ 类的所有方法。

wxNotebook ::GetSelection()返回wxNOT_FOUND或所选页面的索引,然后可用于调用wxNotebook::SetPageText()

或者使用wxNotebook::GetPage()和这个索引来检查它是否等于tab

于 2009-04-05T09:12:20.183 回答
0

我认为做这样的事情会有所帮助:


notebook.get_tab_label(notebook.get_nth_page(your_page_number)).set_text("Your text")

如果您想始终引用当前选项卡,则必须连接“切换页面”信号,并将页面保存在变量中。

于 2009-04-05T08:48:31.803 回答
-1

As .GetPage returns a wx.Window, I think tab.Label = title should work.

于 2009-04-05T08:08:05.783 回答