In this article, you will learn how to build and design your digital clock window using python.
This is a simple project to get started with Tkinter, which is a built-in package that comes with Python. Tkinter is basically a graphical user interface package. It has great features that can be used to create simple applications. And today we will use it to create our digital clock.
The great part of building your own digital clock is you can customize it as you wish. From text font to background color, all the features are available to be customized. If you are ready, let get started!
Python is a general-purpose programming language that is becoming ever more popular for analyzing data. Python also lets you work quickly and integrate systems more effectively. Companies from all around the world are utilizing Python to gather bits of knowledge from their data. The official Python page if you want to learn more.
We will use two libraries in this project. And both of them come with Python, which means we don’t have to install them. These kind of libraries is called Python built-in packages.
The main package we will use is Tkinter. You can learn more about Tkinter from here, the official documentation page.
So for this step, all we need to do is to import them to our program:
from tkinter import Label, Tk
import time
In this step, we will first define the window panel using Tkinter package. And after that, we will define the text design that we want to use for the digital clock.
As mentioned earlier, we will use Tkinter package. Tkinter is can be defined as Tk. And after defining it, we will customize it.
Understanding the code:
Perfect, our application window is ready! Now, let’s work on the clock design.
The cool step of the program is this one. Because you can put your own preferences into the design. This step will make your work different from others. If you love designing things, it’s time to show off your skills.
There are four elements that we will customize:
Here are the values that I used for my design:
For colors, feel free to use RGB values or hex values. In my case, I used the hex values of the colors. I use google’s color picker that is available on the browser. Just search “Color picker” on google search. And you will see it.
Now, let’s combine the elements and define our label. Label function is the text that will show our time.
If you want to learn more about the attributes of the Label function, here is a nice page I found.
If we are working on an application project, functions are the best way to make things work. Functions are also great because they make the program more structured and easier to understand. Alright, let’s define our digital clock function then:
Understanding the code:
Great! You made it until this step, which is the final step of our application project. As you know functions will not run unless you call them. To trigger the application, we will call the function. Let’s run the application:
Well done! You have created a simple digital clock application using only python. Python is a very powerful language and things we can create with python is limitless. It is all about thinking about an idea and making it work. Hoping that you enjoyed reading my article. Working on hands-on programming projects like this one is the best way to sharpen your coding skills.
Behic Guven is a computer scientist with a minor in mathematics. His main focus is in deep learning and artificial intelligence fields. He runs a personal blog with around 600 followers. Besides blogging, he is also making online tutorial videos on Youtube. Other than programming, he enjoys literature, photography and art. He is a nature lover. You can find him at biking trails over the weekends.