How to make a kivy label multiline text?
Last Updated :
24 Nov, 2022
Kivy is an open source software library for the rapid development of applications equipped with novel user interfaces, such as multi-touch apps. Using Kivy on your computer, you can create apps that run on:
- Desktop computers: OS X, Linux, Windows.
- IOS devices: iPad, iPhone.
- Android devices: tablets, phones.
- Any other touch-enabled professional/home brew devices supporting TUIO (Tangible User Interface Objects).
Label in Kivy
The Label widget is for rendering text. It supports ascii and unicode strings. Label is the text which we want to add on our window, give to the buttons and so on. On labels, we can apply the styling also i.e. increase text, size, color and more.
Procedure
- Install kivy on your pc using cmd command “pip install kivy”
- Import kivy and its App module as shown in the example below
- Create a class that inherits the App module
- Define a build method in the class and define the label you want to create in this method and then return the label
- Create an object for the class
- Lastly use run() command for the object
Normal Label Code
Python3
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyDemoApp(App):
def build( self ):
ll = Label(text = "This is a normal label" )
return ll
label = MyDemoApp()
label.run()
|
Output :
Multiline Label Code
You can easily make the text multiline using ‘\n’ at the end of each line.
Example 1 :
Python3
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyDemoApp(App):
def build( self ):
ll = Label(text = "This is a\nmultiline\nlabel" )
return ll
label = MyDemoApp()
label.run()
|
Output :
Example 2 :
Python3
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyDemoApp(App):
def build( self ):
ll = Label(text = "GeeksForGeeks is the \nbest platform for \nDSA content" )
return ll
label = MyDemoApp()
label.run()
|
Output :
Example 3 :
Python3
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyDemoApp(App):
def build( self ):
ll = Label(text =
)
return ll
label = MyDemoApp()
label.run()
|
Output :
Note: For more information on kivy you can visit official docs using this link.
Share your thoughts in the comments
Please Login to comment...