-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
67 lines (53 loc) · 1.75 KB
/
main.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from tkinter import *
import random
BACKGROUND_COLOR = "#BCFFB9"
colors = ["Red", "Blue", "Green", "Black", "Pink", "Yellow", "Orange", "White", "Purple", "Brown"]
score = 0
timeleft = 30
def startgame(event):
if timeleft == 30:
countdown()
next_color()
def next_color():
global score
global timeleft
if timeleft > 0:
entry.focus_set()
if entry.get().lower() == colors[1].lower():
score += 1
entry.delete(0, END)
random.shuffle(colors)
label.config(fg=str(colors[1]), text=str(colors[0]))
score_label.config(text="Score: " + str(score))
def countdown():
global timeleft
if timeleft > 0:
timeleft -= 1
time_label.config(text="Time left: " + str(timeleft))
time_label.after(1000, countdown)
window = Tk()
window.title("PyColor")
window.minsize(width=400, height=350)
window.config(padx=20, pady=20, bg=BACKGROUND_COLOR)
canvas = Canvas(width=350, height=70)
canvas.create_text(
180,
30,
width=330,
text="Type in the color of the words, and not the words!",
font=("Arial", 20, "italic")
)
canvas.config(bg=BACKGROUND_COLOR, highlightthickness=0)
canvas.grid(row=0, column=0, columnspan=2)
score_label = Label(text="Press enter to start", bg=BACKGROUND_COLOR, font=("Arial", 15, "italic"))
score_label.grid( row=1, column=0)
time_label = Label(text="Time left: " + str(timeleft), bg=BACKGROUND_COLOR, font=("Arial", 15, "italic"))
time_label.grid(row=1, column=1)
# A label to display colors
label = Label(bg=BACKGROUND_COLOR, font=("Arial", 25, "italic"))
label.grid(row=2, column=0, columnspan=2)
entry = Entry(width=40)
window.bind("<Return>", startgame)
entry.grid(row=3, column=0, columnspan=2)
entry.focus_set()
window.mainloop()