Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Digital Clock

Description

A simple yet elegant GUI-based digital clock that displays the current time and date. Features a classic matrix-style green-on-black design that updates in real-time.

Features

  • Real-time clock display (HH:MM:SS format)
  • Date display (DD-MM-YYYY format)
  • Matrix-style appearance (green on black)
  • Fast refresh rate (80ms)
  • Clean and minimalist design
  • Non-resizable window for consistent appearance

Stack

  • Language: Python
  • Libraries:
    • tkinter (standard library - Label, Tk)
    • time (standard library - strftime)
    • tk==0.1.0
  • Complexity: Beginner

Installation

# Install dependencies
pip install -r requirements.txt

# Run the program
python main.py

Usage

Simply run the application:

python main.py

The clock will display:

14:35:27
11-10-2025

How It Works

  1. Window Setup: Creates 400x150 pixel window with black background
  2. Label Creation: Large label with green text on black background
  3. Time Update Loop:
    • Get current time using strftime("%H:%M:%S")
    • Get current date using strftime("%d-%m-%Y")
    • Update label text
    • Schedule next update after 80ms using after()

Display Format

Time Format

  • HH: Hours (00-23, 24-hour format)
  • MM: Minutes (00-59)
  • SS: Seconds (00-59)

Date Format

  • DD: Day (01-31)
  • MM: Month (01-12)
  • YYYY: Year (4 digits)

Customization

Change to 12-Hour Format

time_string = strftime("%I:%M:%S %p")  # 02:35:27 PM

Change Date Format

date_string = strftime("%B %d, %Y")  # October 11, 2025
date_string = strftime("%m/%d/%Y")   # 10/11/2025
date_string = strftime("%Y-%m-%d")   # 2025-10-11

Change Colors

# Blue on white
self.root.config(bg="white")
self.clock_label.config(bg="white", fg="blue")

# Red on dark gray
self.root.config(bg="#2c3e50")
self.clock_label.config(bg="#2c3e50", fg="#e74c3c")

Change Font

self.clock_label = tk.Label(
    self.root,
    font=("Courier", 50, "bold"),  # Different font and size
    bg="black",
    fg="green"
)

Change Window Size

self.root.geometry("600x200")  # Larger window

Add Day of Week

time_string = strftime("%H:%M:%S")
date_string = strftime("%A, %d-%m-%Y")  # Monday, 11-10-2025

Learning Outcomes

  • Tkinter GUI basics
  • Time formatting with strftime()
  • Event-driven programming with after()
  • Label widget configuration
  • Window customization

Future Enhancements

  • Multiple time zones
  • Alarm functionality
  • Stopwatch mode
  • Timer mode
  • Theme selection (colors)
  • Font size adjustment
  • Always-on-top option
  • System tray integration
  • Analog clock option
  • World clock (multiple cities)

strftime Format Codes

Code Meaning Example
%H Hour (24-hour) 14
%I Hour (12-hour) 02
%M Minute 35
%S Second 27
%p AM/PM PM
%d Day 11
%m Month (number) 10
%B Month (name) October
%Y Year (4 digits) 2025
%A Weekday (full) Saturday
%a Weekday (short) Sat

License

This project is open source and available for educational purposes.