我想使用 StackLayout 但它只显示一个按钮而不是我预期的两个按钮。代码是:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.uix.stacklayout import StackLayout
from kivy.uix.button import Button
Builder.load_string("""
<ScreenUI>:
orientation: 'lr-bt'
Button:
text: 'Button 1'
Button:
text: 'Button 2'
""")
class ScreenUI(StackLayout):
pass
class WidgetApp(App):
def build(self):
app = ScreenUI()
return app
if __name__ == '__main__':
WidgetApp().run()
如何使用 StackLayout 并添加按钮列表?
更新(包括评论):为了获得我使用的调整大小行为 Builder.load_string("""
<ScreenUI>:
input1: input1
button1: button1
height: self.input1.height
spacing: 5
orientation: 'horizontal'
id: layout1
Label:
text: 'Button 1'
id: button1
size: len(self.text) * root.input1.font_size, 2 * root.input1.font_size
size_hint: None, None
TextInput:
id: input1
text: 'Button 2'
size: root.width - root.button1.width - root.spacing, 2 * self.font_size
size_hint: None, None
""")
是否存在更优雅的方法?