While you can get by writing Kivy applications without ever writing Kivy language (.kv), using the Kivy language may be useful to you for organization and separating application logic from the presentation of it.
It may also boil down to preference in the end. Try both and see what you like best.
Here, we're going to show a very basic implementation of the Kivy language.
from kivy.app import App #kivy.require("1.8.0") from kivy.uix.label import Label class SimpleKivy(App): def build(self): return Label() if __name__ == "__main__": SimpleKivy().run()
This code should be easy enough to follow if you've been following along with the series. Nothing new here.
So what gives? How does this .kv stuff work?
The naming convention for the .kv file needs to follow the main app class, so SimpleKivy should be the name of our .kv file.
So now, let's make the kivy file, calling it SimpleKivy.kv:
#:kivy 1.8.0 <Label> text: 'Hello'+' World!'
So this is our Kivy Language. The tag signs just note that this is the parent, then we have children under it. Here, we're just saying we want to have a label that says "Hello" + "World!"
You could also say text: "Hello world!" I chose to show that you can include some basic Python code as well within the Kivy files.
This is just a basic example, showing the same result as the previous tutorial. The main advantage by using the Kivy language is just for organization. If you have, say, 50 labels in total, 20 buttons, and various other widgets, it will clutter your Python script quite a bit to do all of the styling within it. It might just help for clarity alone to separate the two. Kivy language reminds me a lot of CSS, or stylesheets, for HTML. While you could write all of your styles in line with your HTML, it just makes more sense to separate it.