Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50aaae4

Browse files
Create digital_clock.py
This short Python code gets the local time from the PC as a formatted string using time.strftime('%H:%M:%S'). The time string is displayed in a label using a larger font. A recursive function checks the time five times per second, and updates the time string, if it has changed. Five times per second may sound like overkill, but keeps the display from acting spasmodic.
1 parent 34ebcfe commit 50aaae4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Digital Clock/digital_clock.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# use Tkinter to show a digital clock
2+
import time
3+
from tkinter import *
4+
5+
root = Tk()
6+
7+
root.title("Digital Clock")
8+
root.geometry("250x100+0+0")
9+
root.resizable(0,0)
10+
11+
label = Label(root, font=("Arial", 30, 'bold'), bg="blue", fg="powder blue", bd =30)
12+
label.grid(row =0, column=1)
13+
14+
def dig_clock():
15+
16+
text_input = time.strftime("%H:%M:%S") # get the current local time from the PC
17+
18+
label.config(text=text_input)
19+
20+
# calls itself every 200 milliseconds
21+
# to update the time display as needed
22+
# could use >200 ms, but display gets jerky
23+
24+
label.after(200, clack)
25+
26+
dig_clock()
27+
28+
root.mainloop()

0 commit comments

Comments
 (0)