Python Digital Clock Project:
We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it. |
(1) Open the PyCharm code editor and create a new project in it. We named the project digital_clock.py. To build a Digital Clock in Python we need to install the package. For this open the terminal in PyCharm and install one package i.e. tkinter. You install this package by simply typing in the terminal following command i.e. pip install tk and then press enter as shown below.

Note: f the package shows an error while using in the code, you can simply install the package by clicking on the red bulb which appears below the error and you can directly install the package from here.
(2) Now write the following code for creating Python Digital Clock Project as shown below.


Python Digital Clock Project Source Code:
from tkinter import *
from time import *
def update():
time_str = strftime("%I:%M:%S %p")
time_label.config(text=time_str)
day_str = strftime("%A")
day_label.config(text=day_str)
date_str = strftime("%B %d, %Y")
date_label.config(text=date_str)
clock_window.after(1000,update)
clock_window = Tk()
clock_window.geometry("330x170")
clock_window.title("Digital Clock")
clock_window.config(bg="#CCE3DE")
clock_window.resizable(False,False)
time_label=Label(clock_window,font=("Open Sans",40),bg="#CCE3DE",fg="#00296B")
time_label.pack()
day_label=Label(clock_window,font=("Open Sans",30),bg="#00296B",fg="#CCE3DE")
day_label.pack()
date_label=Label(clock_window,font=("Open Sans",20),bg="#CCE3DE",fg="#00296B")
date_label.pack()
update()
clock_window.mainloop()
(3) After running the code, the output window will pop us as shown below.

Tutorial MySQL Tutorial Python Tokens in C++ Database Management System (DBMS) Applications of Computer Basic Components of Computer System Python (programming language)– Wikipedia |
Comments (No)