From 40417dfcfbebb98d1a416c433f323cebeadb3dbe Mon Sep 17 00:00:00 2001 From: Abdellah El Morabit Date: Sun, 16 Mar 2025 05:50:25 +0100 Subject: added the file --- reactiontime.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 reactiontime.py (limited to 'reactiontime.py') diff --git a/reactiontime.py b/reactiontime.py new file mode 100644 index 0000000..482bd4e --- /dev/null +++ b/reactiontime.py @@ -0,0 +1,48 @@ +import random +import time +from tkinter import * +from tkinter import messagebox + + +def start_game(): + start_time = time.time() + + def show_green_screen(): + root.configure(bg="green") + root.bind("", lambda event, start_time=start_time: check_reaction_time(start_time)) + global randInt + randInt = random.randint(1000, 7000) + root.after(randInt, show_green_screen) # Random delay between 1 to 5 seconds + +def check_reaction_time(start_time): + end_time = time.time() + reaction_time = ((end_time - start_time) * 1000) - randInt # Convert to milliseconds + messagebox.showinfo(title="Reaction Time", message=f"Your reaction time: {reaction_time:.3f} ms") + root.configure(bg="black") + root.unbind("") + + +def toggle_full_screen(): + if root.attributes("-fullscreen"): + root.attributes("-fullscreen", True) + else: + root.attributes("-fullscreen", False) + +def exit_program(): + root.destroy() + +root = Tk() +root.title("ReactionTime") +root.geometry('800x600') +root.configure(bg="black") + +startBtn = Button(root, text="Start", bg="white", fg="black", command=start_game) +startBtn.grid(column=2, row=2) + +fullScreenBtn = Button(root, text="Toggle Fullscreen", bg="white", fg="black", command=toggle_full_screen) +fullScreenBtn.grid(column=4, row=2) + +exitBtn = Button(root, text="Exit", bg="white", fg="black", command=exit_program) +exitBtn.grid(column=8, row=2) + +root.mainloop() -- cgit v1.2.3-70-g09d2