Overview

Kivy 2.0, released on February 8, 2021, drops Python 2 support and introduces a new window backend. This is a major modernization release for the cross-platform framework.

Main Features

Python 3 only

Kivy 2.0 requires Python 3.6 or later. Dropping Python 2 allowed cleaning up the codebase, adopting f-strings, type annotations, and modern Python ecosystem features.

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

class Counter(App):
    def build(self):
        self.count = 0
        layout = BoxLayout(orientation='vertical')

        self.label = Label(
            text=f'Counter: {self.count}',
            font_size='32sp',
        )
        button = Button(
            text='Increment',
            on_press=self.increment,
        )

        layout.add_widget(self.label)
        layout.add_widget(button)
        return layout

    def increment(self, instance):
        self.count += 1
        self.label.text = f'Counter: {self.count}'

Counter().run()

New window backend

A new SDL2-based window provider is available, offering better multi-monitor support, HiDPI handling, and input event management. This backend progressively replaces older providers.

python
# Window backend configuration
# In the ~/.kivy/config.ini file:
# [graphics]
# window_state = visible
# width = 800
# height = 600

from kivy.config import Config

# Configuration via code
Config.set('graphics', 'width', '1024')
Config.set('graphics', 'height', '768')
Config.set('graphics', 'resizable', '1')

# The SDL2 backend is automatically selected
# on supported platforms (Linux, macOS, Windows)
from kivy.core.window import Window
print(f'Size: {Window.size}')
print(f'DPI: {Window.dpi}')

Sources