In this video I’ll show you how to use python in your .kv design files.
Can we use actual Python on a Kivy .kv file? Well….sort of! I’ll show you how to do it in this video.
#kivy #codemy
Python Code: code.py
GitHub Code: code.py
from kivy.lang import Builder
from kivymd.app import MDApp
class MainApp(MDApp):
some_text = "Hello World!"
our_list = ["John", "Mary", "Tina"]
def build(self):
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = "BlueGray"
return Builder.load_file('code.kv')
MainApp().run()
Kivy Design Code: code.kv
GitHub Code: code.kv
MDFloatLayout:
MDRaisedButton:
text: app.some_text
pos_hint: {'center_x': .5, 'center_y': .5}
on_release:
for i in app.our_list:\
our_label.text = our_label.text + "\n" + i
MDLabel:
id: our_label
text: ""
pos_hint: {'center_x': .95, 'center_y': .4}

Add comment