Clock using KIVY Python

This blog discusses simple clock project using kivy and Python. This app is a simple UI clock app.

To build this app, I have used two widgets BoxLayout and Label. BoxLayout is a one dimension widget which contain Label as a child widget. Layout for this app is build using Builder string.

Below modules imported for this app.

import kivy
from import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from datetime import datetime
from kivy.clock import Clock

Kivy clock module for calling a function every 1 second and updating the time on the clock app. Importing datetime module to use strftime function in code. Importing BoxLayout and Label from kivy.

Creating string which contains BoxLayout and Label.

kv ='''


In the below program, creating ClockApp() class with App as a base class and displaying content of builder string using return statement.

Method on_start() has clock schedule which calls method update() every 1 second. Method update() display day and time on the Label text. Used markup for applying color, size and making text bold. Set markup property to True to use it on our program. In the above kivy string, we have set markup property to True inside Label widget.

Strfime() function :- Represent date and time in string format. It takes one or more formatted code and returns string representation. Syntax : – strftime(format). It requires datetime module

Below formatted code use in our program.

  • $A -> Display Full Weekday
  • %d -> Display day of the month
  • %B -> Full month name
  • %Y -> Year
  • %I -> Hour in 12 format
  • %M -> Minutes
  • %S -> Seconds

Displaying weekday on the first line, date on the second line and time at the bottom. Used \n new line character.

class ClockApp(App):
    def build(self):
        return Builder.load_string(kv)

    def on_start(self):

    def update(self,nap): = '[color=#a84232]'+'[size=120]'+strftime('%A')+'[/size]'+'[/color]' '[color=#85a832]'+'[size=90]'+strftime('%d %B, %Y')+'[/size]'+'[/color]'
        self.time = '[color=#9e3898]'+'[size=80]'+strftime('%I:%M:%S')+'[/size]'+'[/color]'
        self.root.ids.time_day.text = '[b]''\n''\n'+self.time+'[/b]'




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s