How to add custom fonts in Kivy – Python?
Last Updated :
03 Oct, 2022
Prerequisites: Kivy Tutorial
Kivy is a platform-independent GUI tool in Python. It can run on Android, IOS, Linux and Windows, etc. This is the only GUI library from python which can independently run on the android device even we can use it on Raspberry pi also. It is an open-source Python library for the rapid development of multi-touch applications. Its graphic engine is built over OpenGL, and it supports fast graphics pipeline.
In this article, we will develop a GUI window using kivy framework of Python, and we will add a button on this window and we will add our own font style on this button’s text. For this task you should have a custom font style, don’t worry if you don’t have yours you can download from this link here you will get ample of font styles you can also download and unzip them. After unzipping you will get files in .ttf format keep those files because they are holding the actual font styles.
Step-by-step approach:
Basic Approach for using the custom font in kivy application:
- Import button
- Import kivyApp
- Import labelbase
- Import builder
- Create App class
- Return layout
- Run an instance of the class
Implementation:
Python3
from kivy.uix.button import Button
from kivy.app import App
from kivy.core.text import LabelBase
from kivy.lang import Builder
class uiApp(App):
def build( self ):
return Builder.load_string(
)
LabelBase.register(name = 'Lemonada' ,
fn_regular = 'Lemonada-VariableFont_wght.ttf' )
uiApp().run()
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...