Displaying ‘Hello World!’ using kivy language file

In this blog, we will create a simple application that displays text ‘Hello World!’ in the label widget.

In the previous blog, we have used label widget to display ‘Hello World!’ message directly by defining text property from the same file. In this program, we will use another kivy file for defining property of the label widget.

Both kivy and python file should in same directory.

Create a python file with importing kivy module

from kivy.app import App
from kivy.uix.label import Label

Create subclass TestApp. App is the base class for TestApp

class TestApp(App):
def build(self):
return Label()

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

There are two files. test.py and test.kv

Below is the content of file test.py

from kivy.app import App
from kivy.uix.label import Label

class TestApp(App):
def build(self):
return Label()

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

Below is the content of kivy file test.kv

<Label>:
text : 'Hello World!'

Make sure that filename of a kivy file should match with subclass. For example, if we create subclass DoAPP then the kivy filename should be do.kv

Output

Advertisement

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s