StackLayout(Kivy)中的对象顺序 [英] Object order in StackLayout (Kivy)
问题描述
我有一个
layout = StackLayout()
现在我把这样的按钮
for x in range(9): # range() explanation: http://pythoncentral.io/pythons-range-function-explained/
bt = Button(text=' ', font_size=200, width=200, height=200, size_hint=(None, None), id=str(x+1))
bt.bind(on_release=self.btn_pressed)
layout.add_widget(bt)
问题是当我遍历layout.children数组并显示其ID时,它们依次出现在9,8,7,6,5,4,3,2,1
中,而不是我想要的.我怎样才能使它们处于适当的顺序? (反转数组不是解决方案)
the problem is that when I go through layout.children array and show the ids they come in order 9,8,7,6,5,4,3,2,1
which is reversed and not what I want. How do I get them in proper order? (Reversing the array is not a solution)
另一个例子
我有:
self.layout = StackLayout()
bt = Button(text='1', font_size=200, width=200, height=200, size_hint=(None, None), id="1")
bt1 = Button(text='2', font_size=200, width=200, height=200, size_hint=(None, None), id="2")
bt2 = Button(text='3', font_size=200, width=200, height=200, size_hint=(None, None), id="3")
bt3 = Button(text='4', font_size=200, width=200, height=200, size_hint=(None, None), id="4")
bt4 = Button(text='5', font_size=200, width=200, height=200, size_hint=(None, None), id="5")
bt5 = Button(text='6', font_size=200, width=200, height=200, size_hint=(None, None), id="6")
self.layout.add_widget(bt, 1)
self.layout.add_widget(bt1, 2)
self.layout.add_widget(bt2, 3)
self.layout.add_widget(bt3, 4)
self.layout.add_widget(bt4, 5)
self.layout.add_widget(bt5, 6)
这向我显示了以下内容:
And this shows me this:
推荐答案
Kivy出于与内部调度顺序有关的原因而在此处颠倒了顺序.并非必须如此,但这是一个设计决定.
Kivy reverses the order here for reasons to do with internal dispatching order. It doesn't have to, but it's a design decision.
但是,这根本不重要.如果您想将对象存储在某种特定的结构中,请自己做.
However, this really doesn't matter at all. If you want to store your objects in some particular structure, do that yourself.
这篇关于StackLayout(Kivy)中的对象顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!