Clock App with Kivy using Python Last Updated : 29 Nov, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we are going to see how to develop a Clock Application with Kivy using Python. Kivy is a graphical user interface opensource Python library that allows you to develop multi-platform applications on Windows, macOS, Android, iOS, Linux, and Raspberry-Pi. In addition to the regular mouse and keyboard inputs, it also supports multitouch events. We will be using the time module to get the current time and update it every second. Moreover, we will be also be displaying two times of different timezones. Functions Usedasctime(): By default gets the local time. You can also pass the time zone in it to get the time of another zone as done in Example 2.BoxLayout(): It is used to arrange layouts in vertical or horizontal boxes.schedule_interval(): Is used to create time intervals and recall the function/event.add_widget(): Adds widget to the screen.Example 1: Local time app using kivy Python3 # importing modules # it will allow us to get time import time # The App class is the base for # creating Kivy applications from kivy.app import App # it will allow us to make interval calls from kivy.clock import Clock # Label widget will be used to render text from kivymd.uix.label import Label # we will be using this to resize app window from kivy.core.window import Window # it will allow us to create layouts from kivy.uix.boxlayout import BoxLayout # declaring window size Window.size = (400, 700) # clock class class myclock(Label): def update(self, *args): # get the current local time self.text = time.asctime() # App class class TimeApp(App): def build(self): layout = BoxLayout(orientation='vertical') # it will create vertical layouts in app # calling clock class for time clock1 = myclock() # updates time with the interval of 1 sec Clock.schedule_interval(clock1.update, 1) # adding layout to the screen layout.add_widget(clock1) # adding text to screen layout.add_widget(Label(text='INDIA')) return layout root = TimeApp() root.run() # running the app Output: Code Explanation The code starts with importing the modules that we need to use.The first module is time which will allow us to get the current local time.Next, it imports the Clock class which will be used for scheduling updates of myclock widget.It then creates a new app called TimeApp and builds it by adding a layout boxlayout and text label.The code is a sample of how to create an application with the Kivy framework.The first line imports modules that will allow us to get time and use it in our code.Line 3 declares the App class which is the base for creating Kivy applications.It allows us to make interval calls, add widgets, and return layouts.Line 4 creates a new instance of myclock widget which renders text.Line 5 schedules 1 second update intervals on clock1 by calling Clock.schedule_interval().Line 6 adds layout to screen with widgets added and returns layout as result of build() function call.Line 7 adds text to screen with Label widget added and returns layout as result of build() function call.Example 2: Adding another time zone in the time app Create another clock class and Add an extra layout for clock 2 in-app class. Python3 import time from kivy.app import App from kivy.clock import Clock from kivymd.uix.label import Label from kivy.core.window import Window from kivy.uix.boxlayout import BoxLayout Window.size = (400, 700) class myclock(Label): def update(self, *args): self.text = time.asctime() class myclock2(Label): def update(self, *args): t = time.gmtime() self.text = time.asctime(t) class TimeApp(App): def build(self): layout = BoxLayout(orientation='vertical') clock1 = myclock() Clock.schedule_interval(clock1.update, 1) layout.add_widget(clock1) layout.add_widget(Label(text='INDIA')) clock2 = myclock2() Clock.schedule_interval(clock2.update, 1) layout.add_widget(clock2) layout.add_widget(Label(text='LONDON')) return layout root = TimeApp() root.run() Output: Code Explanation: The code starts by creating two Label widgets.The first is myclock1 and the second is myclock2.They are both created with a function called update, which takes no arguments and returns nothing.This means that when they are updated, their text will be set to the current time in asctime().The next step is to create a BoxLayout widget with an orientation of 'vertical'.It then adds these two Label widgets to it.Finally, it creates another BoxLayout widget but this one has an orientation of 'horizontal' and adds those two Label widgets again.The code is designed to create a widget that displays the current time on screen.The first widget, myclock1, will update every second and display the current time in text form.The second widget, myclock2, will update every second and display the current time in text form with an extra line of text at the top displaying the difference between seconds (in this case 1). Comment More infoAdvertise with us Next Article Clock App with Kivy using Python vinamrayadav Follow Improve Article Tags : Python Geeks Premier League Geeks-Premier-League-2022 Python-kivy Practice Tags : python Similar Reads Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio 10 min read Python Interview Questions and Answers Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth 15+ min read Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Python OOPs Concepts Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p 11 min read Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list 10 min read Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test 9 min read Python Programs Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co 11 min read Enumerate() in Python enumerate() function adds a counter to each item in a list or other iterable. It turns the iterable into something we can loop through, where each item comes with its number (starting from 0 by default). We can also turn it into a list of (number, item) pairs using list().Let's look at a simple exam 3 min read Python Data Types Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes 9 min read Steady State Response In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We 9 min read Like