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
15 changes: 13 additions & 2 deletions DigitalClock/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## Digital Clock with Tkinter

A digital clock using python and the Tkinter library.

Sample clock:
![](https://github.com/larymak/Python-project-Scripts/blob/main/DigitalClock/Capture.PNG)
### Code
A Clock class is created, with two instance method, one
for setting purposes (in this case to set the name of the clock),
and the `widgets` method, which holds the actual business logic.
This method uses a nested method that is responsible for
setting the current time and start counting from it.\
The Clock will have a random color.

### Sample clock:

![clock sample](./clock-sample.JPG)
Binary file added DigitalClock/clock-sample.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions DigitalClock/clock.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
# import GUI library - Tkinter
import tkinter as tk
import time
import random


class Clock:
colors = ['red', 'blue', 'green', 'black', 'orange', 'purple', 'brown', 'yellow', 'pink']

def __init__(self):
# instance of Tkinter window
self.master = tk.Tk()
self.color = random.choice(Clock.colors)

def settings(self):
# Label the window to "My Clock"
self.master.title('My Clock')

def widgets(self):
#Time calculation
def counttime(time1=''):
# Time calculation
def count_time(time1=''):
time2 = time.strftime('%H:%M:%S')
if time2 != time1:
time1 = time2
clock.config(text=time2)
clock.after(200, counttime)
clock.after(200, count_time)
# Create the clock text
clock = tk.Label(self.master, font=('Poppins', 50, 'bold'), background='blue', foreground='white')
clock = tk.Label(self.master, font=('Poppins', 50, 'bold'), background=self.color, foreground='white')
clock.pack(anchor='center')
# Clock loop
counttime()
count_time()
tk.mainloop()


if __name__ == '__main__':
my_clock = Clock()
my_clock.settings()
Expand Down