Hidden Gems in the App Development Realm💎: Kivy and KivyMD

Tanishq Pokharia
DataX Journal
Published in
5 min readNov 17, 2023

The Great Beginner Dilemma

When it comes to building mobile apps, developers have a multitude of options , Kotlin/Java for native android development, Swift for iOS development, and Flutter for cross platform app development. Newbies might be confused as to what to choose and how to proceed. What if they could begin their journey into the world of app development with a language most beginners are familiar with? Well, Kivy and KivyMD helps them with just that. It helps you dive into the world of app development using Python.

But why Python? Python is known for its simplicity and readability, making it an excellent choice for beginners. Its extensive community support and numerous libraries further enhance the development experience. Kivy harnesses the power of Python and extends it to mobile app development.

What are Kivy and KivyMD?

Kivy is an open source, cross-platform Python framework for the development of cross platform applications , which means that you can use Kivy to build software that can run on various operating systems, including Windows, macOS, Linux, Android, and iOS.

As for KivyMD, it is an extension Kivy which provides Material Design compliant widgets , which makes your app look more native, stylish and mobile friendly. It helps developers to approximate Google’s Material Design spec as close as possible without sacrificing ease of use.

Both of Kivy and KivyMD are open-sourced on Github and people are free to contribute to them.

Getting Started

Some basic pre-requisites before learning Kivy are:

  1. Object Oriented Programming knowledge in Python
  2. Python IDE - I recommend PyCharm but you can use VS Code or any other IDE of your choice
  3. Tons of curiosity :)

Installation:

Install the following dependencies using your terminal:

pip install kivy[full]
pip install kivymd

Creating your first app

Here is a sample code to creating your first basic Kivy app:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button

class HelloWorldApp(App):
def build(self):
layout = BoxLayout(orientation='vertical')
self.message = Label(text="")
button = Button(text="Show Message")
button.bind(on_press=self.show_message)
layout.add_widget(self.message)
layout.add_widget(button)
return layout

def show_message(self, instance):
self.message.text = "Hello World!"

if __name__ == '__main__':
HelloWorldApp().run()

Kivy also introduces us to kv language, it is a domain-specific language (DSL) designed specifically for creating user interfaces in the Kivy framework. It works on tags and declarations so those familiar with html or xml will easily get it. It handles all your UI components for you so that organizing your app becomes easier. It has a .kv extension.

Here is the same app made with kv language + python:

Python:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

class HelloWorldApp(BoxLayout):
def show_message(self):
self.ids.message.text = "Hello World!"

class HelloWorldKivyApp(App):
def build(self):
return HelloWorldApp()

if __name__ == '__main__':
HelloWorldKivyApp().run()

KV language:

<HelloWorldApp>:
orientation: 'vertical'

Label:
text: ""

Button:
text: "Show Message"
on_release: root.show_message()

Now, if we use KivyMD our app looks like this:

from kivymd.app import MDApp
from kivymd.uix.relativelayout import MDRelativeLayout
from kivymd.uix.label import MDLabel
from kivymd.uix.button import MDRaisedButton

class HelloWorldApp(MDApp):
def build(self):
layout = MDRelativeLayout()
self.message = MDLabel(text="", halign="center", valign="middle")
button = MDRaisedButton(text="Show Message", pos_hint={"center_x": 0.5, "center_y": 0.4})
button.bind(on_press=self.show_message)
layout.add_widget(self.message)
layout.add_widget(button)
return layout

def show_message(self, instance):
self.message.text = "Hello World!"

if __name__ == '__main__':
HelloWorldApp().run()

As you learn more about Kivy and KivyMD and reach an intermediate level, you will be able to create a lot more complex and better apps like this:

Kivy and KivyMD VS Flutter

Kivy and KivyMD often compete with Flutter as both are technologies used to build cross platform mobile applications and follow similar widget hierarchy. Let us see how they compare and contrast:

Resources

Here are some awesome resources to help you, should you get stuck anywhere in your Kivy and KivyMD journey :) :-

Kivy docs: https://kivy.org/doc/stable/

KivyMD docs: https://kivymd.readthedocs.io/

Codemy.com Youtube Playlist: https://www.youtube.com/watch?v=dLgquj0c5_U&list=PLCC34OHNcOtpz7PJQ7Tv7hqFBP_xDDjqg&pp=iAQB

KivyMD Official Youtube channel: https://www.youtube.com/@KivyMD

Conclusion

So all in all, Kivy and KivyMD can be a great choice for learning the basics of app development, how widgets work and how frontend and backend of apps are integrated. It is important to consider their long-term viability and industrial presence. But as of now, Kivy and KivyMD apps do not have significant presence in the industry when compared to more established options like native Android (Kotlin/Java) and iOS (Swift) development or cross-platform solutions such as Flutter. Kivy and KivyMD are still growing and developing ,so nobody knows yet whether in future there are going to be job prospects to KivyMD app development yet but itcannot be underestimated.

However, understanding the core concepts and principles of app development using Kivy and KivyMD can be a valuable learning experience that will transfer well to other development paths in the future and I will say it is definitely worth a shot if you are a beginner!

I hope this article lit a kindle of curiosity in you towards Kivy and KivyMD.

Happy coding :))

--

--