In this video I’ll show you how to set default layout properties for widgets and then inherit them into all your widgets.

Say you’ve got a bunch of buttons in your app. You can manually set the button color and font size etc for each button, or you can set it once and inherit that default setting for all the buttons.

I’ll show you how in this video!

Python Code: inherit.py
GitHub Code: inherit.py

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.lang import Builder

# Designate Our .kv design file 
Builder.load_file('inherit.kv')
class MyLayout(Widget):
	pass
	
class AwesomeApp(App):
	def build(self):
		return MyLayout()


if __name__ == '__main__':
	AwesomeApp().run()


Kivy Design Code: inherit.kv
GitHub Code: inherit.kv

<Button>
	font_size: 32
	background_normal: ''
	background_color: (0,0,1,1)

<TextInput>
	background_color: (150/255,150/255,150/255,1)	

<Label>
	font_size: 32

<MyLayout>
	BoxLayout:
		orientation: "vertical"
		size: root.width, root.height
		padding:10
		spacing:10

		Label:
			text: "Name"

		TextInput:
			multiline: False

		Label:
			text: "Favorite Pizza"

		TextInput:
			multiline: False

		Button:
			text: "Submit"
		Button:
			text: "Clear"
			background_color: (1,0,0,1)

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