test-kivy-app/kivy_venv/share/kivy-examples/kv/builder_template.py

29 lines
614 B
Python
Raw Normal View History

2024-09-15 12:12:16 +00:00
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
[BlehItem@BoxLayout]:
orientation: 'vertical'
Label:
text: str(ctx.idx)
Button:
text: ctx.word
''')
class BlehApp(App):
def build(self):
root = BoxLayout()
for idx, word in enumerate(('Hello', 'World')):
wid = Builder.template('BlehItem', **{
'idx': idx, 'word': word,
})
root.add_widget(wid)
return root
if __name__ == '__main__':
BlehApp().run()