更改 wx.Notebook 中选项卡的标题
我正在尝试使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道 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.
我认为这样做会有所帮助:
如果您想始终引用当前选项卡,则必须连接“switch-page”信号,并将页面保存在变量中。
I think doing something like this helps :
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.
由于 .GetPage 返回一个 wx.Window,我认为
tab.Label = title
应该可以工作。As .GetPage returns a wx.Window, I think
tab.Label = title
should work.