From 8089f1b46fa77b18ced797ccd6b8b18903e58a40 Mon Sep 17 00:00:00 2001 From: Yousuf Date: Thu, 1 Feb 2024 11:44:32 -0500 Subject: [PATCH 1/2] enhanced-clock-display --- projects/Alarm Clock/clock.py | 37 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/projects/Alarm Clock/clock.py b/projects/Alarm Clock/clock.py index 5f80e40f0..40a2fd2a5 100644 --- a/projects/Alarm Clock/clock.py +++ b/projects/Alarm Clock/clock.py @@ -1,27 +1,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.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", @@ -29,10 +40,10 @@ def time(): ) # 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() From 981dac32b6903f5e01e1748d8bbd5c1264d92e92 Mon Sep 17 00:00:00 2001 From: Yousuf Date: Fri, 2 Feb 2024 01:16:56 -0500 Subject: [PATCH 2/2] Enhanced Tile Matching Game --- projects/Tile Matching/tile_matching.py | 39 +++++++++++++++---------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/projects/Tile Matching/tile_matching.py b/projects/Tile Matching/tile_matching.py index ed2cc6122..5c9925add 100644 --- a/projects/Tile Matching/tile_matching.py +++ b/projects/Tile Matching/tile_matching.py @@ -1,7 +1,6 @@ import tkinter as tk import random -from tkinter import messagebox # Import the messagebox module - +from tkinter import messagebox class TileMatchingGame: def __init__(self, root, rows, columns): @@ -19,14 +18,14 @@ def __init__(self, root, rows, columns): def create_board(self): all_colors = [ - "salmon", - "lightblue", - "azure", - "darkblue", - "orange", - "purple", - "pink", - "brown", + "lightcoral", + "lightseagreen", + "lightsteelblue", + "lightgoldenrodyellow", + "lightsalmon", + "lightgreen", + "lightpink", + "lightcyan", ] colors = random.sample(all_colors, self.rows * self.columns // 2) colors *= 2 # Duplicate colors to have pairs @@ -103,9 +102,13 @@ def check_matching_tiles(self): self.end_game() else: - self.tiles[tile1[0]][tile1[1]].config(text="", bg="gray") - self.tiles[tile2[0]][tile2[1]].config(text="", bg="gray") - self.selected_tiles = [] + self.root.update_idletasks() + self.root.after(500, self.hide_unmatched_tiles, tile1, tile2) + + def hide_unmatched_tiles(self, tile1, tile2): + self.tiles[tile1[0]][tile1[1]].config(text="", bg="gray") + self.tiles[tile2[0]][tile2[1]].config(text="", bg="gray") + self.selected_tiles = [] def end_game(self): self.timer_label.config(text="Game Over!") @@ -118,6 +121,9 @@ def get_tile_position(self, tile): col = row_tiles.index(tile) return row, col + def reset_game(self): + self.root.destroy() + main() def main(): root = tk.Tk() @@ -127,12 +133,15 @@ def main(): game = TileMatchingGame(root, rows, columns) + # Reset Button + reset_button = tk.Button(root, text="Reset Game", command=game.reset_game) + reset_button.grid(row=rows + 3, columnspan=columns) + # Exit Button exit_button = tk.Button(root, text="Exit", command=root.destroy) - exit_button.grid(row=rows + 3, columnspan=columns) + exit_button.grid(row=rows + 4, columnspan=columns) root.mainloop() - if __name__ == "__main__": main()