How todo a transparent background digital desktop clock with Python

Sebastian Bocanegra
2 min readAug 10, 2021

--

Digital Clock

If you you are a Python passionate and if you like to decorate your desktop setup this blog is for you.

If you don’t know anything about Python programming language this is a powerful programming language which is easily to undersand and help you todo whatever you want without any complication. So if that’s your case I strongly recommend that you learn it.

Now if you are a Python experienced developer or if you are beginning in this world, this blog show you how to do a digital clock easily, that you can start to use it when you finish of develop it.

First import from tkinter module the Label, mainloop and Tk objects. For the next step import the datetime module. This will help us to create a Label UI widget which holds the text of our system current time.

Let’s go to instantiate the Tk class, assign it a title (this is optional). For the next step we’re going to obtain the height and width of the screen that you are using. This is for maintaine centered the label and when you let your computer sleeping this widget doesn’t loose its initial position.

At this part we define the behavior of the the clock dots, if the current second is pair the widget will render the colon on the Label Widget else it doesn’t render.

Now we’re going to format the string which will placed into the Label Widget at the format like this MONDAY, JAN 21 and in a new line 10:20:20 AM in case of the current time is before midday.

Almost the end, we must instantiate the object of the Label Widget, give it properties like font family, font size, background etc. If you remember that at the beginning we stored the height and width of the screen into variables with the same name. We need put it into the label widget configurations to avoid changes in the position of the widget when the system wake up. After that change make the background transparent to give it the aspect of a desktop gadget.

To finish configurations, we need to center the window and set up it to fullscreen to make sure the current date time always be centered. Now our digital clock is finished.

I will let you the link of the repository on my github for full access to the code.

pydigital_clock

--

--

Sebastian Bocanegra

Software developer. Solving daily troubles with the tool of the code