如何从 wxStatusBar 中删除字段

发布于 2024-08-09 12:41:35 字数 249 浏览 1 评论 0原文

这可能是显而易见的,但我错过了。我在 wxpython 工作。

我有一个带有几个字段的 wxStatusBar (这些字段有文本以及其他小部件)。我需要能够在整个应用程序会话中添加和删除这些字段。有没有办法从状态栏中删除字段,或者我只需要重新绘制它?我认为要做后者,我可以使用 SetFields() 函数,但我不太确定要给 SetFields() 提供什么类型的列表...我见过的唯一示例给出了一个字符串列表,但我有更多的字符串来传递它。

提前致谢!

This may be obvious, but I'm missing it. I'm working in wxpython.

I have a wxStatusBar with several fields (these fields have text as well as other widgets). I need to be able to add and remove these fields throughout the app session. Is there a way to remove fields from a statusbar, or do I just have to redraw it? I think to do the latter I could use the SetFields() function, but I'm not quite sure what type of list to give SetFields()...the only example I've seen gives it a list of strings, but I have more than strings to pass it.

Thanks in advance!

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

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

发布评论

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

评论(1

旧伤慢歌 2024-08-16 12:41:35

您可以通过调用 mystatusbar.SetFieldsCount(numfields) 来减少字段数量。如果需要,可以使用 .SetStatusWidths([list]) 重新缩放它们。使用 .SetStatusText('string',position) 更改各个位置的文本。如果您在状态栏部分隐藏了某些控件(例如复选框),您可以将其移动到 .GetFieldRect(position) 指定的位置。在 wx.EVT_SIZE 上或每当您删除/消除东西时调用此函数。

如果您从末尾(最高索引)以外的位置删除字段,则必须首先手动移动数据。您提到您正在使用 .SetFields(),只需取出您之前传递的列表并 .pop() 取出您不需要的列表。

wxPython 演示中的一些重新定位代码:

# reposition the checkbox
def Reposition(self):
    rect = self.GetFieldRect(1) # the checkbox lives in the 2nd (index 1) slot
    self.cb.SetPosition((rect.x+2, rect.y+2))
    self.cb.SetSize((rect.width-4, rect.height-4))
    self.sizeChanged = False

wxPython 演示应用 中查找一些示例代码,您可以快速查看破解并从其中运行。

You can reduce the number of fields by calling mystatusbar.SetFieldsCount(numfields). Rescale them if desired with .SetStatusWidths([list]). Change text at individual positions using .SetStatusText('string', position). If you have some control (e.g. a checkbox) hiding in a status bar section, you can move it to the spot given by .GetFieldRect(position). Call this on wx.EVT_SIZE or whenever you remove/eliminate stuff.

If you remove fields from somewhere other than the end (highest index), you'll have to manually shift your data first. You mentioned you were using .SetFields(), just take the list you passed earlier and .pop() out the one you don't want.

Some repositioning code from wxPython demo:

# reposition the checkbox
def Reposition(self):
    rect = self.GetFieldRect(1) # the checkbox lives in the 2nd (index 1) slot
    self.cb.SetPosition((rect.x+2, rect.y+2))
    self.cb.SetSize((rect.width-4, rect.height-4))
    self.sizeChanged = False

Look in the wxPython Demo app for some example code you can quickly hack up and run from within it.

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