当所有小部件都在Kivy中展示时,是否有一些事件?

时间:2014-08-11 22:25:10

标签: python widget kivy python-3.4

我有3个布局,第2个大小取决于另外两个布局的孩子的宽度:

def on_size(self, *args):
    self.left_panel.width = max(child.texture_size[0] for child in self.left_panel.children) + self.side_padding
    self.right_panel.width = max(child.texture_size[0] for child in self.right_panel.children) + self.side_padding
    available_space = self.width - self.left_panel.width - self.right_panel.width
    if available_space > self.height:
        self.middle_panel.size = (self.height, self.height)
        extra = (self.width - self.height - self.left_panel.width - self.right_panel.width) // 2
        self.left_panel.width += extra
        self.right_panel.width += extra
    else:
        self.middle_panel.size = (available_space, available_space)
    self.middle_panel.calculate_points()
    self.middle_panel.clear_widgets()
    self.middle_panel.redraw_blocks()

由于某种原因,它仅在50%的情况下(随机)正常工作。如果它加载了worng,那么在我调整窗口大小后它就变得正确了。另外,现在我在另外两个Layouts的每个孩子的on_size()触发时调用它,这是个坏主意。是否存在某些事件或者当所有内容都被加载/呈现时?

更新

这是应该的(有时是)。 enter image description here

但有时会发生随机的下一个问题(请参阅右侧的按钮): enter image description here

更新

现在我称之为:

class SideButton(Button):
    def on_size(self, *args):
        self.parent.parent.on_size()

我知道这不是一个好主意,因为它触发了30-50次smth,但我不能更好地发明smth。

0 个答案:

没有答案