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}		
		
			

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder