1

我正在使用 Phil 的 PyGame Utilities (PGU)。我有一个区域需要显示不断变化的可滚动变量列表。这是一个调试窗口,应该在变量更改时显示它们的实时更新。我已经尝试使用几种不同的小部件和几种不同的方式来执行此操作,但是当我在更新循环中更新小部件时,滚动条锁定问题。

我最初的想法是在列表中放置标签,然后更改标签并调用更新或重绘函数,但我似乎无法让它工作。为了让它工作,我完全清除了我正在使用的小部件,并在每个更新循环中重新添加所有标签。这会导致滚动条出现问题并损害我的帧速率。

以下是我认为它应该如何工作:

self.l = gui.List(width = self.config['uiwidth']-10, height = self.config['height']-230)
self.add(self.l, 5, 255)

self.label = gui.Label("UNCHANGED",align=-1)

    if self.firstTimeSelectingBot == True:
        for i in range(len(dbot.customDebugVariableList)):
            self.l.add(self.label, value = i)
        self.firstTimeSelectingBot = False
    self.label = gui.Label("CHANGED",align=-1)
    self.label.repaint()

它将标签添加到列表中,然后更改标签。我认为调用 repaint 会重新绘制标签以显示新标签,但没有任何变化。我已经用表格和列表尝试过这个,但我可以让它显示的唯一方法是购买完全清除列表/表格并重新添加导致滚动条和帧率问题的所有内容。

有什么帮助或想法吗?谢谢。

4

1 回答 1

0

You want to use label.set_text to change the text on the label. So using your code as an example

self.l = gui.List(width = self.config['uiwidth']-10, height = self.config['height']-230)
self.add(self.l, 5, 255)

self.label = gui.Label("UNCHANGED",align=-1)

    if self.firstTimeSelectingBot == True:
        for i in range(len(dbot.customDebugVariableList)):
            self.l.add(self.label, value = i)
        self.firstTimeSelectingBot = False
    self.label.set_text("CHANGED")

You will note however that the alignment was taken out. Label.set_text fails when you put it in however the alignment set when label was created stays so as long as you don't need to change that this works. Take a look at pgu/gui/basic.py lines 96-129 for the label class itself which is how I figured this out (I also was looking for the answer on my own).

于 2015-03-04T00:55:52.173 回答