如何更改 Kivy 堆栈布局中按钮的方向

How can I change the orientation of a buttons in a stack layout in Kivy

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.stacklayout import StackLayout


class mylayout(StackLayout):
    def __init__(self, **kwargs):
        super(mylayout, self).__init__(**kwargs)
        for i in range(10):
            btn = Button(text=str(i), width=40, size_hint=(None, 0.15), orientation= 'lr-bt')
            self.add_widget(btn)


class NameApp(App):
    def build(self):
        mL = mylayout()
        return mL

if __name__ == "__main__":
    NameApp().run()

我已经尝试更改此处的方向,但应用程序上显示的方向仍然是默认方向

方向是 属性 布局的方向,而不是它包含的小部件的方向。您可以使用

self.orientation = "lr-bt"

__init__ 函数中将 属性 分配给布局。如果您使用它,您也可以将其分配到适当的 .kv 文件中。