summaryrefslogtreecommitdiff
path: root/reactiontime.py
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2025-03-16 05:50:25 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2025-03-16 05:50:25 +0100
commit40417dfcfbebb98d1a416c433f323cebeadb3dbe (patch)
treef688717fde6c1795cdc5bcf886e0dd78de92f080 /reactiontime.py
parent491b510a9e00b454c8075e0c532c1b002483d051 (diff)
added the fileHEADmain
Diffstat (limited to 'reactiontime.py')
-rw-r--r--reactiontime.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/reactiontime.py b/reactiontime.py
new file mode 100644
index 0000000..482bd4e
--- /dev/null
+++ b/reactiontime.py
@@ -0,0 +1,48 @@
1import random
2import time
3from tkinter import *
4from tkinter import messagebox
5
6
7def start_game():
8 start_time = time.time()
9
10 def show_green_screen():
11 root.configure(bg="green")
12 root.bind("<Button-1>", lambda event, start_time=start_time: check_reaction_time(start_time))
13 global randInt
14 randInt = random.randint(1000, 7000)
15 root.after(randInt, show_green_screen) # Random delay between 1 to 5 seconds
16
17def check_reaction_time(start_time):
18 end_time = time.time()
19 reaction_time = ((end_time - start_time) * 1000) - randInt # Convert to milliseconds
20 messagebox.showinfo(title="Reaction Time", message=f"Your reaction time: {reaction_time:.3f} ms")
21 root.configure(bg="black")
22 root.unbind("<Button-1>")
23
24
25def toggle_full_screen():
26 if root.attributes("-fullscreen"):
27 root.attributes("-fullscreen", True)
28 else:
29 root.attributes("-fullscreen", False)
30
31def exit_program():
32 root.destroy()
33
34root = Tk()
35root.title("ReactionTime")
36root.geometry('800x600')
37root.configure(bg="black")
38
39startBtn = Button(root, text="Start", bg="white", fg="black", command=start_game)
40startBtn.grid(column=2, row=2)
41
42fullScreenBtn = Button(root, text="Toggle Fullscreen", bg="white", fg="black", command=toggle_full_screen)
43fullScreenBtn.grid(column=4, row=2)
44
45exitBtn = Button(root, text="Exit", bg="white", fg="black", command=exit_program)
46exitBtn.grid(column=8, row=2)
47
48root.mainloop()