This is a simple digital clock application created using Python's tkinter library. The clock displays the current time and updates every second.
- Displays the current time in
HH:MM:SS AM/PMformat. - Shows the current day of the week.
- Uses a digital font for a stylish look.
- Updates every second to ensure the time is always accurate.
- Python 3.x
-
Clone the repository or download the
clock.pyfile.git clone https://github.com/nomankarim8/digital-clock.git cd digital-clock -
Make sure you have the
tkinterlibrary installed. This library usually comes pre-installed with Python, but if you need to install it, you can use the following command:pip install tk
-
Navigate to the directory containing the
clock.pyfile. -
Run the
clock.pyscript.python clock.py
-
A window will appear displaying the current time and day of the week.
-
Imports:
from tkinter import * from tkinter.ttk import * from time import strftime
-
Root Window:
root = Tk() root.title("Clock")
-
Time Function: The
timefunction fetches the current time and updates the label every second.def time(): string = strftime('%H:%M:%S %p %a') label.config(text=string) label.after(1000, time)
-
Label: The label is used to display the time with a specified font, background, and foreground color.
label = Label(root, font=('ds-digital', 80), background='black', foreground='cyan') label.pack(anchor='center')
-
Initialize Time and Mainloop: The
timefunction is called once to initialize the clock, andmainloopis used to run the application.time() mainloop()
Created by nomankarim8
This project is licensed under the MIT License - see the LICENSE file for details.
This `README.md` file provides an overview of the project, installation instructions, usage guide, and an explanation of the code.