Skip to content

Commit 213217c

Browse files
authored
PR #25: Digital Clock
Add Digital Clock Project. Merge pull request #25 from DarkSlayer102/Digital_Clock
2 parents 140553a + e4944c2 commit 213217c

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

Digital_Clock/README.MD

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Digital Clock
2+
3+
A simple Python-based digital clock application with a graphical user interface built using `Tkinter`. This project displays the current time in real-time and is designed to be visually appealing, lightweight, and customizable.
4+
5+
---
6+
7+
## Features
8+
9+
- **Real-Time Clock Display:**
10+
Displays the current time in `HH:MM:SS` format and updates every second.
11+
12+
- **Customizable Design:**
13+
Easily modify the clock’s font, colors, and layout to suit your preferences.
14+
15+
- **Header Label:**
16+
Includes a "Time Clock" header for a professional and organized look.
17+
18+
- **User-Friendly Interface:**
19+
The application features a clean and vibrant design for an engaging user experience.
20+
21+
- **Lightweight and Fast:**
22+
Built with `Tkinter`, the application runs efficiently without consuming significant system resources.
23+
24+
---
25+
26+
## How It Works
27+
28+
1. **Initialization:**
29+
The `DigitalClock` class sets up the main window, configures its appearance, and initializes the clock and header.
30+
31+
2. **Real-Time Updates:**
32+
The `update_time_on_clock` method retrieves the current system time and updates the clock display every second using `Tkinter`'s `after()` method.
33+
34+
3. **Execution:**
35+
The application runs continuously, keeping the time accurate until the user closes the window.
36+
37+

Digital_Clock/digital_clock.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from tkinter import Tk, Label
2+
from tkinter.font import Font
3+
import time
4+
5+
6+
class DigitalClock:
7+
def __init__(self, font=None):
8+
"""Initialize the digital clock."""
9+
self.create_window()
10+
self.configure_window()
11+
self.set_font(font)
12+
self.add_header()
13+
self.add_clock()
14+
self.update_time_on_clock()
15+
16+
def create_window(self):
17+
"""Create the main window."""
18+
self.window = Tk()
19+
20+
def configure_window(self):
21+
"""Configure the main window properties."""
22+
self.window.title('Digital Clock')
23+
self.window.config(bg='black')
24+
25+
def set_font(self, customFont):
26+
"""Set the font for the clock display."""
27+
DEFAULT_FONT = Font(family='Arial', size=90, weight='normal')
28+
self.font = customFont if customFont is not None else DEFAULT_FONT
29+
30+
def add_header(self):
31+
"""Add a header label to the window."""
32+
self.header = Label(self.window, text='Time Clock',
33+
font=self.font, bg='gray', fg='white')
34+
self.header.grid(row=1, column=2)
35+
36+
def add_clock(self):
37+
"""Add the clock label to the window."""
38+
self.clock = Label(self.window, font=(
39+
'times', 90, 'bold'), bg='blue', fg='white')
40+
self.clock.grid(row=2, column=2, padx=620, pady=250)
41+
42+
def update_time_on_clock(self):
43+
"""Update the time displayed on the clock every second."""
44+
currentTime = time.strftime("%H:%M:%S")
45+
self.clock.config(text=currentTime)
46+
self.clock.after(1000, self.update_time_on_clock)
47+
48+
def start(self):
49+
"""Start the Tkinter main loop."""
50+
self.window.mainloop()
51+
52+
53+
if __name__ == "__main__":
54+
clock = DigitalClock()
55+
clock.start()
56+

0 commit comments

Comments
 (0)