Python - Add Label to kivy window


Kivy is an pen source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. It is used to develop the Android application, as well as Desktops applications. In this article we will see how to add labels to the windows created through Kivy.

Creating Label

In the below example we create a window and give it a custom label by using Label function available in uix.lable module. Once we run the app with this code we get the new window showing the custom label.

Example

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

class NewLabel(App):
   def build(self):
      # Label text to be edited
      lbl = Label(text ="Hello Label Text ! ")
      return lbl

NewLabel().run()

Running the above code gives us the following result −

Output

decorating the Label

We can also adjust the font size and colour of the label with additional parameters available as part of the Label function.

Example

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

class NewLabel(App):
   def build(self):
      # Label text to be edited
      lbl = Label(text ="Hello Label Text ! \nwelcome to the world of Kivy",font_size='30sp',color = [0.56, 0.56, 0.24, 1])
      return lbl
NewLabel().run()

Running the above code gives us the following result −

Output

Updated on: 28-Dec-2020

508 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements