forked from Mrinank-Bhowmick/python-beginner-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.py
More file actions
38 lines (28 loc) · 983 Bytes
/
clock.py
File metadata and controls
38 lines (28 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Importing the necessary modules
import tkinter
from time import strftime
# Creating the main application window
top = tkinter.Tk()
top.title("Clock") # Setting the title of the window
top.resizable(0, 0) # Making the window non-resizable
# Function to update the time display
def time():
# Get the current time in the format HH:MM:SS AM/PM
string = strftime("%H:%M:%S %p")
# Update the text of the clockTime Label with the current time
clockTime.config(text=string)
# Schedule the time function to be called again after 1000 milliseconds (1 second)
clockTime.after(1000, time)
# Creating a Label widget to display the time
clockTime = tkinter.Label(
top,
font=("courier new", 40),
background="black",
foreground="white",
)
# Position the Label widget in the center of the window
clockTime.pack(anchor="center")
# Call the time function to start updating the time display
time()
# Start the Tkinter main event loop
top.mainloop()