Kivy 在布局末尾添加小部件

Kivy add widget at the end of layout

kivy doc中有函数add_widget(widget, index=0, canvas=None),我们必须能够设置一个索引来定位小部件。

index: int, defaults to 0

Index to insert the widget in the list. Notice that the default of 0 means the widget is inserted at the beginning of the list and will thus appear under the other widgets. For a full discussion on the index and widget hierarchy, please see the Widgets Programming Guide.

因此,首先我尝试对小部件顺序进行任何更改的任一索引。然后我想在列表的末尾而不是开头插入我的小部件。

如果你有想法:)

我找到了解决方案:

self.add_widget(your_widget, len(self.children))

如果你打印 self.children 你会看到对象添加在列表的末尾,它会反转视图上的显示顺序。