Python – KivyMD Fonts

Table of Contents

Intro

How to get in KivyMD your Costum Font running with a easy example Code.

Basic Code

				
					from kivymd.font_definitions import theme_font_styles
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.core.text import LabelBase
KV = '''
Screen:

    MDLabel:
        text: "Rubik"
        halign: "center"
        font_style: "Rubik"

'''


class MainApp(MDApp):
    def build(self):
        LabelBase.register(
            name="Rubik",
            fn_regular="../assets/fonts/Rubik/Rubik-Regular.ttf")

        theme_font_styles.append('Rubik')
        self.theme_cls.font_styles["Rubik"] = [
            "Rubik",
            16,
            False,
            0.15,
        ]
        return Builder.load_string(KV)


MainApp().run()
				
			

Leave a Reply