Skip to content

Commit 506c638

Browse files
committed
random color, comments added, documentation updated
1 parent 807f6b0 commit 506c638

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

DigitalClock/README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1+
## Digital Clock with Tkinter
2+
13
A digital clock using python and the Tkinter library.
24

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

DigitalClock/clock-sample.JPG

17.3 KB
Loading

DigitalClock/clock.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
# import GUI library - Tkinter
22
import tkinter as tk
33
import time
4+
import random
5+
46

57
class Clock:
8+
colors = ['red', 'blue', 'green', 'black', 'orange', 'purple', 'brown', 'yellow', 'pink']
9+
610
def __init__(self):
11+
# instance of Tkinter window
712
self.master = tk.Tk()
13+
self.color = random.choice(Clock.colors)
814

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

1319
def widgets(self):
14-
#Time calculation
15-
def counttime(time1=''):
20+
# Time calculation
21+
def count_time(time1=''):
1622
time2 = time.strftime('%H:%M:%S')
1723
if time2 != time1:
1824
time1 = time2
1925
clock.config(text=time2)
20-
clock.after(200, counttime)
26+
clock.after(200, count_time)
2127
# Create the clock text
22-
clock = tk.Label(self.master, font=('Poppins', 50, 'bold'), background='blue', foreground='white')
28+
clock = tk.Label(self.master, font=('Poppins', 50, 'bold'), background=self.color, foreground='white')
2329
clock.pack(anchor='center')
2430
# Clock loop
25-
counttime()
31+
count_time()
2632
tk.mainloop()
2733

34+
2835
if __name__ == '__main__':
2936
my_clock = Clock()
3037
my_clock.settings()

0 commit comments

Comments
 (0)