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
# importing button widget from kivy frameworkfrom kivy.uix.button import Buttonfrom kivy.app import App # importing labelbase which which # register our custom font for applicationfrom kivy.core.text import LabelBasefrom kivy.lang import Builder # this is the main class which will# render the whole applicationclass uiApp(App): # method which will render our application def build(self): return Builder.load_string(""" # adding our buttonButton: # text which will appear on first button text:"first button" # specifying the fontstyle name that we # have registered in main.py file font_name:"Lemonada" font_size:65 """) # registering our new custom fontstyleLabelBase.register(name='Lemonada', fn_regular='Lemonada-VariableFont_wght.ttf') # running the applicationuiApp().run() |
Output:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


