更改 wx.Notebook 中选项卡的标题

发布于 2024-07-15 22:34:00 字数 612 浏览 6 评论 0原文

我正在尝试使用wxPython,

我有一个选项卡式界面(笔记本),每个选项卡基本上都是一个文件列表视图(是的,我正在尝试制作一个文件管理器)

文件列表继承自wx.ListCtrl,并且选项卡式界面继承自 wx.Notebook

我刚刚开始..并且我有它,因此双击文件夹将 cd 进入该文件夹,但我还想更改选项卡的标题。

我怎么做?

我有代表文件列表的对象和我想要将其设置为的标题,

[ EDIT Notebook.SetPageText() 需要一个数字,所以我无法将选项卡对象直接传递给它 ]

我当前的方法是循环浏览选项卡,直到其中一个选项卡与我的选项卡匹配:

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

但这看起来相当天真,难道没有更聪明的方法吗方法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里梦着梦中梦 2024-07-22 22:34:00

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

wxNotebook::GetSelection() 返回 wxNOT_FOUND 或所选页面的索引,然后可以使用它来调用wxNotebook::SetPageText()< /em>.

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

I don't know wxPython, but I assume it wraps all the methods of the C++ classes.

There is wxNotebook::GetSelection() which returns wxNOT_FOUND or the index of the selected page, which can then be used to call wxNotebook::SetPageText().

Or use wxNotebook::GetPage() with this index to check whether it is equal to tab.

同展鸳鸯锦 2024-07-22 22:34:00

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


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

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

I think doing something like this helps :


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

If you want to have a reference to the current tab always, you must connect the "switch-page" signal, and save the page in a variable.

大海や 2024-07-22 22:34:00

由于 .GetPage 返回一个 wx.Window,我认为 tab.Label = title 应该可以工作。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文