Simple Digital Clock with Python (TUTORIAL).

How to create a Simple Digital Clock with Python??





HI, 
IN THIS BLOG I WILL SHOW YOU HOW TO CREATE A SIMPLE DIGITAL CLOCK WITH PYTHON, THIS IS GOING TO BE SUPER FUN SO LET'S GET STARTED.


FIRST OF ALL LET'S IMPORT THE MODULES REQUIRED FOR THE PROJECT:

HERE IS TH CODE:

from tkinter import Label, Tk
import time


HERE WE WILL BE USING TKINTER FOR THIS PROJECT AND ABSOLUTLY TIME.

NOW WE WANT TO MAKE THE ARRANGEMENTS TO MAKE THE APP LOOK BEAUTIFUL TO SEE.

 LET'S DO IT WITH THIS CODE:

app_window = Tk()
app_window.title("Digital Clock")
app_window.geometry("420x150")
app_window.resizable(1,1)

text_font= ("Boulder", 68, 'bold')
background = "#f2e750"
foreground= "#363529"
border_width = 25

THIS IS THE CODE THAT DETERMINE THE APP WANT TO LOOK LIKE.


NEXT WE CAN WE HAVE TO ADD THE DESIGN VARIABLES TO THE LABELS WHICH WILL OPTIMIZE THE LOOK.

CODE: 
label = Label(app_window, font=text_font, bg=background, fg=foreground, bd=border_width)
label.grid(row=0, column=1)

 
ATLAST WE HAVE TO CODE FOR THE TIME TO DISPLAY IN THE APP. IT'S SUPER EASY TO DO.

CODE:

def digital_clock():
time_live = time.strftime("%H:%M:%S")
label.config(text=time_live)
label.after(200, digital_clock)


AND THEN WE HAVE TO CALL THE FUNCTION TO RUN THE CLOCK.

CODE:

digital_clock()
app_window.mainloop()


AND RUN THE FULL CODE IT WILL DISPLAY THE OUTPUT AS DIGITAL CLOCK.





SO THIS PROJECT IS SUPER SIMPLE TO DO AND ALL THE BEGINNERS MUST TRY THIS PROJECTS.



FULL CODE:

from tkinter import Label, Tk
import time
app_window = Tk()
app_window.title("Digital Clock")
app_window.geometry("420x150")
app_window.resizable(1,1)

text_font= ("Boulder", 68, 'bold')
background = "#f2e750"
foreground= "#363529"
border_width = 25

label = Label(app_window, font=text_font, bg=background, fg=foreground, bd=border_width)
label.grid(row=0, column=1)

def digital_clock():
time_live = time.strftime("%H:%M:%S")
label.config(text=time_live)
label.after(200, digital_clock)

digital_clock()
app_window.mainloop()


THANK YOU WE WILL MEET IN THE NEXT INTERESTING PROJECT.



IMPORTANT UPDATE:

IN FUTURE PROJECTS WE WILL BE IMPLEMENTING MACHINE LEARNING ALGORITHMS SO STAY TUNED.

THANK YOU.