Build a Match-3 Game using Python and Kivy

Lesson 1 of 8

Kivy: Setup and Installation

Kivy is a Python framework for building cross-platform apps and games, the same codebase can run on Windows, macOS, Linux, Android, and iOS. It's especially popular for 2D games with touch controls: puzzle games, card games, simple platformers, and, in this project, a Match-3 game in the style of Candy Crush.

Installing Kivy

Like Pygame, Kivy needs a real window to draw into, so it doesn't run inside this course's browser sandbox. Write and run this project locally with a real Python install.

pip install kivy

Verify it installed correctly:

import kivy
print(kivy.__version__)

Your first Kivy app

Every Kivy app is a class that extends App, with a build() method that returns the single root widget the whole app is drawn from.

from kivy.app import App
from kivy.uix.label import Label

class Match3App(App):
    def build(self):
        return Label(text='Match-3, coming soon!', font_size=32)

if __name__ == '__main__':
    Match3App().run()
  • App.run() opens the window and starts Kivy's own event loop (similar in spirit to Pygame's while running: loop, but Kivy manages it for you).
  • build() is called once, at startup, whatever widget it returns becomes the entire visible app, later lessons will return a full game board here instead of a single Label.

Packaging for mobile

This course focuses on getting the game working on your desktop, but Kivy code is written with mobile in mind from the start. When you're ready to ship, Buildozer packages a Kivy app into a real Android APK:

pip install buildozer
buildozer init
buildozer -v android debug

buildozer init generates a buildozer.spec file describing your app (name, permissions, dependencies), and buildozer android debug builds the actual installable APK. You won't need Buildozer for this course's lessons, it's mentioned here so you know the path from "Python script" to "installable app" exists and is just one command away.

NOTE

Buildozer only runs on Linux (or WSL on Windows). It's completely optional for following this course, everything here runs and is testable as a normal desktop Python app.

📝 Kivy Setup Quiz

Passing score: 70%
  1. 1.What must every Kivy app class extend?

  2. 2.A Kivy app's build() method is called repeatedly, once per frame.

  3. 3.____ packages a finished Kivy app into an installable Android APK.