From 6ef7a72515b7d722278f6694a271493111d33731 Mon Sep 17 00:00:00 2001 From: DarkSlayer102 <55598746+DarkSlayer102@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:55:10 +0530 Subject: [PATCH 1/6] I have included my Digital_Clock into the Python-Projects folder --- Digital_Clock/digital_clock.py | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Digital_Clock/digital_clock.py diff --git a/Digital_Clock/digital_clock.py b/Digital_Clock/digital_clock.py new file mode 100644 index 0000000..d18c883 --- /dev/null +++ b/Digital_Clock/digital_clock.py @@ -0,0 +1,56 @@ + +from tkinter import * +import time +from tkinter.font import Font + +''' +In this project, I have imported all the necessary packages, including time and Tkinter. Tkinter is a built-in library that enables the creation of Graphical User Interfaces (GUIs). +''' + + +def clocks(): + ''' + This function displays the current time. + ''' + currentTime = time.gmtime() + currentTime = f'{currentTime.tm_hour}:{currentTime.tm_min}:{currentTime.tm_sec}' + clock.config(text=currentTime) + clock.after(200, clocks) + ''' +This is simply printing out to verify whether it is functioning correctly or not. + ''' + print("Working Properly") + + +''' +Here I created a instance of TK class +''' +window = Tk() +# creating a title +window.title("Digital Clock") +# creating background color +window.config(bg="black") + +font1 = Font(family="Arial", size=90, weight="normal") +# creating a header using Label Widget +header = Label(window, text="Time Clock", font=font1, bg="gray", fg="white") +# using grid() to place the header somewhere comfortable in the gui +header.grid(row=1, column=2) +''' +A clock is being constructed using the Label Widget, which exhibits the current time and is positioned using grid. +''' +clock = Label(window, font=("times", 90, "bold"), bg="blue", fg='white') +clock.grid(row=2, column=2, padx=620, pady=250) + +''' + +calling the function here +''' +clocks() + +''' +running the main window +''' +if __name__ == "__main__": + + window.mainloop() From e95c7567f1cbcf24a2a8e9dc728234a579250896 Mon Sep 17 00:00:00 2001 From: DarkSlayer <55598746+DarkSlayer102@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:18:27 +0530 Subject: [PATCH 2/6] Update Digital_Clock/digital_clock.py Suggestion has been added in respect of the following best practice Co-authored-by: Shamith --- Digital_Clock/digital_clock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Digital_Clock/digital_clock.py b/Digital_Clock/digital_clock.py index d18c883..22af039 100644 --- a/Digital_Clock/digital_clock.py +++ b/Digital_Clock/digital_clock.py @@ -1,5 +1,5 @@ -from tkinter import * +import tkinter as tk import time from tkinter.font import Font From c6978d4f17926a0ba986e4fcf296335db3299800 Mon Sep 17 00:00:00 2001 From: DarkSlayer <55598746+DarkSlayer102@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:30:32 +0530 Subject: [PATCH 3/6] Update digital_clock.py I have updated the code as pre requested. Specifically, following the best practices that has been suggested --- Digital_Clock/digital_clock.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Digital_Clock/digital_clock.py b/Digital_Clock/digital_clock.py index 22af039..dd76e3e 100644 --- a/Digital_Clock/digital_clock.py +++ b/Digital_Clock/digital_clock.py @@ -1,4 +1,3 @@ - import tkinter as tk import time from tkinter.font import Font @@ -25,7 +24,7 @@ def clocks(): ''' Here I created a instance of TK class ''' -window = Tk() +window = tk.Tk() # creating a title window.title("Digital Clock") # creating background color @@ -33,13 +32,13 @@ def clocks(): font1 = Font(family="Arial", size=90, weight="normal") # creating a header using Label Widget -header = Label(window, text="Time Clock", font=font1, bg="gray", fg="white") +header = tk.Label(window, text="Time Clock", font=font1, bg="gray", fg="white") # using grid() to place the header somewhere comfortable in the gui header.grid(row=1, column=2) ''' A clock is being constructed using the Label Widget, which exhibits the current time and is positioned using grid. ''' -clock = Label(window, font=("times", 90, "bold"), bg="blue", fg='white') +clock = tk.Label(window, font=("times", 90, "bold"), bg="blue", fg='white') clock.grid(row=2, column=2, padx=620, pady=250) ''' From 5a4535794fc1ef507a6eb5e0626304abf906970f Mon Sep 17 00:00:00 2001 From: DarkSlayer <55598746+DarkSlayer102@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:35:40 +0530 Subject: [PATCH 4/6] Update Digital_Clock/digital_clock.py Removing unnecessary comments Co-authored-by: Shamith --- Digital_Clock/digital_clock.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Digital_Clock/digital_clock.py b/Digital_Clock/digital_clock.py index dd76e3e..57dc757 100644 --- a/Digital_Clock/digital_clock.py +++ b/Digital_Clock/digital_clock.py @@ -2,9 +2,6 @@ import time from tkinter.font import Font -''' -In this project, I have imported all the necessary packages, including time and Tkinter. Tkinter is a built-in library that enables the creation of Graphical User Interfaces (GUIs). -''' def clocks(): From 4aac33a64ae2cc941f2372a1d4dc6a9a199ca25f Mon Sep 17 00:00:00 2001 From: DarkSlayer <55598746+DarkSlayer102@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:53:18 +0530 Subject: [PATCH 5/6] Update digital_clock.py All main suggestions have been included in the code. --- Digital_Clock/digital_clock.py | 96 ++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/Digital_Clock/digital_clock.py b/Digital_Clock/digital_clock.py index 57dc757..5e11037 100644 --- a/Digital_Clock/digital_clock.py +++ b/Digital_Clock/digital_clock.py @@ -1,52 +1,56 @@ -import tkinter as tk -import time +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() -def clocks(): - ''' - This function displays the current time. - ''' - currentTime = time.gmtime() - currentTime = f'{currentTime.tm_hour}:{currentTime.tm_min}:{currentTime.tm_sec}' - clock.config(text=currentTime) - clock.after(200, clocks) - ''' -This is simply printing out to verify whether it is functioning correctly or not. - ''' - print("Working Properly") - - -''' -Here I created a instance of TK class -''' -window = tk.Tk() -# creating a title -window.title("Digital Clock") -# creating background color -window.config(bg="black") - -font1 = Font(family="Arial", size=90, weight="normal") -# creating a header using Label Widget -header = tk.Label(window, text="Time Clock", font=font1, bg="gray", fg="white") -# using grid() to place the header somewhere comfortable in the gui -header.grid(row=1, column=2) -''' -A clock is being constructed using the Label Widget, which exhibits the current time and is positioned using grid. -''' -clock = tk.Label(window, font=("times", 90, "bold"), bg="blue", fg='white') -clock.grid(row=2, column=2, padx=620, pady=250) - -''' - -calling the function here -''' -clocks() - -''' -running the main window -''' if __name__ == "__main__": + clock = DigitalClock() + clock.start() - window.mainloop() From e4944c25c55bd8465387264bd08911d5c4fc3c2a Mon Sep 17 00:00:00 2001 From: DarkSlayer <55598746+DarkSlayer102@users.noreply.github.com> Date: Mon, 23 Dec 2024 15:56:08 +0530 Subject: [PATCH 6/6] Create README.MD --- Digital_Clock/README.MD | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Digital_Clock/README.MD diff --git a/Digital_Clock/README.MD b/Digital_Clock/README.MD new file mode 100644 index 0000000..263da1f --- /dev/null +++ b/Digital_Clock/README.MD @@ -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. + +