forked from CaMeLCa5e/daily
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypeColor.py
72 lines (43 loc) · 1.25 KB
/
TypeColor.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
#!/usr/bin/python
import tkinter
import random
colors = ['Red', 'Blue', 'Green', 'Pink', 'Yellow', 'Orange', 'White', 'Purple', 'Brown']
score = 0
timeLeft = 30
def startGame(event):
if timeLeft == 30:
countdown()
nextColor()
def nextColor():
global score
global timeLeft
if timeLeft > 0:
e.focus_set()
if e.get().lower() == colors[1].lower():
score += 1
e.delete(0, tkinter.END)
random.shuffle(colors)
label.config(fg=str(colors[1]), text=str(colors[0]))
scoreLabel.config(text='Score: '+ str(score))
def countdown():
global timeLeft
if timeLeft > 0:
timeLeft -= 1
timeLabel.config(text='Time left: ' + str(timeLeft))
timeLabel.after(1000, countdown)
root = tkinter.Tk()
root.title("Color Countdown")
root.geometry("375x200")
instructions = tkinter.Label(root, text="Type the color of the text", font=('Helvetica', 12))
instructions.pack()
scoreLabel = tkinter.Label(root, text="Press enter to start", font=('Helvetica', 12))
scoreLabel.pack()
timeLabel = tkinter.Label(root, text=" Time Left" + str(timeLeft), font=('Helvetica', 12))
timeLabel.pack()
label = tkinter.Label(root, font=('Helvetica', 60))
label.pack()
e = tkinter.Entry(root)
root.bind('<Return>', startGame)
e.pack()
e.focus_set()
root.mainloop()