Create A Digital Clock Using Python
In this post, we will create a digital clock using python. To create it, python and sublime (or similar) are required.
First of all, create a folder as a place to store the python files to be created. I created a C: / digitalclock folder.
Then open a command prompt and install the Tkinter package with the command
pip install tk
After completing the installation of the tkinter package, the next step is to open the sublime (or the like) to write the syntax. Write the import package syntax with the command
import sys
from tkinter import *
import time
Then write the function definition times to display the digital clock in the form of hours, minutes, and seconds with syntax
def times():
current_time=time.strftime("%H:%M:%S")
clock.config(text=current_time)
clock.after(200,times)
The point of the clock.after command is that the digital clock continues its time when it is recorded.
Then make the desired output geometry size. Here I want to use the size 500x250 with the command
root=Tk()
root.geometry("500x250")
Then create a label where the first label is a digital clock which will be displayed using the font times new roman, size 50 bold, with a white clock background. The second label is the title of the digital clock, namely “Indonesia Bagian Barat” which will be displayed using the font times new roman, size 14 bold. And the third label is the label of hours minutes seconds or “hours minutes seconds” which will be displayed using the font times new roman, size 15 bold. As for the meaning of x = and y =, namely the size of the desired label placement.
clock=Label(root,font=("times",50,"bold"),bg="white")
clock.place(x=10,y=40)
times()
digi=Label(root,text="Waktu Indonesia Bagian Barat", font="times 14 bold")
digi.place(x=30,y=5)
nota=Label(root,text="hours minutes seconds", font="times 15 bold")
nota.place(x=10,y=120)root.mainloop()
The combination of all the commands above, namely
Then save the file with the .py extension in the digital clock folder created earlier.
To call, open a command prompt then type digiclock.py (syntax file name).
Then a digital clock output will appear that corresponds to the current clock.
FINISH!
Digital clock made!
May be usefull…