Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates theme switching between light and dark using canvas colors.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.graphics import Color, Rectangle
class ThemeApp(App):
def build(self):
self.dark = False
self.layout = BoxLayout()
self.button = Button(text='Switch Theme', on_press=lambda x: self.toggle_theme())
self.layout.add_widget(self.button)
self.update_bg()
return self.layout
def update_bg(self):
self.layout.canvas.before.clear()
with self.layout.canvas.before:
Color(0.1, 0.1, 0.1) if self.dark else Color(1, 1, 1)
Rectangle(size=self.layout.size, pos=self.layout.pos)
def toggle_theme(self):
self.dark = not self.dark
self.update_bg()
if __name__ == '__main__':
ThemeApp().run()Kivy is an open-source Python framework for building cross-platform multitouch applications on Android, iOS, Windows, macOS, Linux, and Raspberry Pi. It provides a UI toolkit, gesture support, animations, layouts, and a declarative KV language for rapid app development.
Origin & Creator
Kivy was created by Mathieu Virbel and the Kivy Organization, evolving from the PyMT project and released publicly in 2011 as a modern Python GUI + mobile app framework.
Industrial Note
Kivy is especially loved in education, research environments, rapid prototyping, Raspberry Pi projects, and Python-first development teams requiring cross-platform touch UIs.