Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Digital_Clock/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Digital Clock

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.

---

## Features

- **Real-Time Clock Display:**
Displays the current time in `HH:MM:SS` format and updates every second.

- **Customizable Design:**
Easily modify the clock’s font, colors, and layout to suit your preferences.

- **Header Label:**
Includes a "Time Clock" header for a professional and organized look.

- **User-Friendly Interface:**
The application features a clean and vibrant design for an engaging user experience.

- **Lightweight and Fast:**
Built with `Tkinter`, the application runs efficiently without consuming significant system resources.

---

## How It Works

1. **Initialization:**
The `DigitalClock` class sets up the main window, configures its appearance, and initializes the clock and header.

2. **Real-Time Updates:**
The `update_time_on_clock` method retrieves the current system time and updates the clock display every second using `Tkinter`'s `after()` method.

3. **Execution:**
The application runs continuously, keeping the time accurate until the user closes the window.


56 changes: 56 additions & 0 deletions Digital_Clock/digital_clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from tkinter import Tk, Label
from tkinter.font import Font
import time


class DigitalClock:
def __init__(self, font=None):
"""Initialize the digital clock."""
self.create_window()
self.configure_window()
self.set_font(font)
self.add_header()
self.add_clock()
self.update_time_on_clock()

def create_window(self):
"""Create the main window."""
self.window = Tk()

def configure_window(self):
"""Configure the main window properties."""
self.window.title('Digital Clock')
self.window.config(bg='black')

def set_font(self, customFont):
"""Set the font for the clock display."""
DEFAULT_FONT = Font(family='Arial', size=90, weight='normal')
self.font = customFont if customFont is not None else DEFAULT_FONT

def add_header(self):
"""Add a header label to the window."""
self.header = Label(self.window, text='Time Clock',
font=self.font, bg='gray', fg='white')
self.header.grid(row=1, column=2)

def add_clock(self):
"""Add the clock label to the window."""
self.clock = Label(self.window, font=(
'times', 90, 'bold'), bg='blue', fg='white')
self.clock.grid(row=2, column=2, padx=620, pady=250)

def update_time_on_clock(self):
"""Update the time displayed on the clock every second."""
currentTime = time.strftime("%H:%M:%S")
self.clock.config(text=currentTime)
self.clock.after(1000, self.update_time_on_clock)

def start(self):
"""Start the Tkinter main loop."""
self.window.mainloop()


if __name__ == "__main__":
clock = DigitalClock()
clock.start()

Loading