Make a digital clock using python in just 13 lines of code.




In this post, I will teach you how to make a digital clock using Python. Step by Step:

Step1:

Firstly you need a code editor to run your python code. you may choose any code editor like Pycharm , VS code anyone with you are comfortable. but I personally recommend you Pycharm. Because it is easy to use and you can easily download any python library in it just using terminal.


Step2:

Secondly, you need to install Python on your machine. Because if you can install Python on your machine the program will not work. and it will show an error to you in your console.
So, you need to install the latest version of python. from the official website of Python.

Interface of the website

Step3:

Now you need to create a new project with any name(eg: name.py). after this, you get a space for coding. 

Step4:

Now write the code in your code editor:

Source Code:



from tkinter import *
from tkinter.ttk import *
from time import strftime
root=Tk()
root.title("Hello World! this is my clock")

def time():
    string=strftime('%H:%M:%S %p')
    label.config(text=string)
    label.after(1000,time)

label=Label(root,font=("ds-digital",80),background="red",foreground="yellow")
label.pack(anchor='center')
time()
mainloop()


Step5: 

Now run the Code. and you will see a clock like this (Shown in the picture below)




Video Tutorial

Comments