-
Notifications
You must be signed in to change notification settings - Fork 681
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #698 from KhwajaYousuf/feature/enhanced-tile-match…
…ing-game Feature/enhanced tile matching game
- Loading branch information
Showing
2 changed files
with
48 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,49 @@ | ||
# 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.title("Dynamic Clock") # Updated title | ||
top.resizable(0, 0) # Making the window non-resizable | ||
|
||
# Function to determine the time of day | ||
def get_time_of_day(hour): | ||
if 5 <= hour < 12: | ||
return "Morning" | ||
elif 12 <= hour < 18: | ||
return "Afternoon" | ||
else: | ||
return "Evening" | ||
|
||
# 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") | ||
def update_time(): | ||
current_time = strftime("%H:%M:%S %p") | ||
hour = int(strftime("%H")) | ||
time_of_day = get_time_of_day(hour) | ||
|
||
# Update the text of the clockTime Label with the current time | ||
clockTime.config(text=string) | ||
# Update the text of the clockTime Label with the current time and time of day | ||
clock_time.config(text=current_time + f"\nGood {time_of_day}!") | ||
|
||
# Schedule the time function to be called again after 1000 milliseconds (1 second) | ||
clockTime.after(1000, time) | ||
# Dynamically change the background color based on time of day | ||
color = "lightblue" if time_of_day == "Morning" else "lightyellow" if time_of_day == "Afternoon" else "lightcoral" | ||
top.configure(background=color) | ||
|
||
# Schedule the update_time function to be called again after 1000 milliseconds (1 second) | ||
clock_time.after(1000, update_time) | ||
|
||
# Creating a Label widget to display the time | ||
clockTime = tkinter.Label( | ||
clock_time = 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") | ||
clock_time.pack(anchor="center") | ||
|
||
# Call the time function to start updating the time display | ||
time() | ||
# Call the update_time function to start updating the time display | ||
update_time() | ||
|
||
# Start the Tkinter main event loop | ||
top.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters