1. Home
  2. /
  3. Kivy
  4. /
  5. Stopwatch Example

Stopwatch Example - Kivy Typing CST Test

Loading…

Stopwatch Example — Kivy Code

A simple stopwatch that starts, stops, and resets using Clock scheduling.

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

class StopwatchApp(App):
	def build(self):
		self.time = 0
		self.running = False
		self.layout = BoxLayout(orientation='vertical', padding=20)
		self.label = Label(text='0.0', font_size=32)
		self.layout.add_widget(self.label)
		self.layout.add_widget(Button(text='Start', on_press=lambda x: self.start()))
		self.layout.add_widget(Button(text='Stop', on_press=lambda x: self.stop()))
		self.layout.add_widget(Button(text='Reset', on_press=lambda x: self.reset()))
		return self.layout

	def update(self, dt):
		self.time += dt
		self.label.text = f'{self.time:.1f}'

	def start(self):
		if not self.running:
		self.running = True
		Clock.schedule_interval(self.update, 0.1)

	def stop(self):
		self.running = False
		Clock.unschedule(self.update)

	def reset(self):
		self.time = 0
		self.label.text = '0.0'

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

Kivy Language Guide

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.

Primary Use Cases

  • ▸Mobile apps (Android/iOS)
  • ▸Touchscreen kiosks and dashboards
  • ▸Cross-platform GUI apps in Python
  • ▸Prototyping and educational tools
  • ▸Raspberry Pi and hardware interfaces

Notable Features

  • ▸KV language for declarative UI
  • ▸GPU-accelerated rendering
  • ▸Multitouch gesture framework
  • ▸Cross-platform build tools
  • ▸Rich widget and layout system

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.

More Kivy Typing Exercises

Kivy Counter ExampleKivy Todo List AppKivy Theme SwitcherKivy Slider ExampleKivy Login UI ExampleKivy Toggle Button ExampleKivy Color Picker ExampleKivy Calculator ExampleKivy Image Viewer Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher