-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcolorgame.py
112 lines (76 loc) · 3.17 KB
/
colorgame.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from tkinter import *
import random
from tkinter import messagebox
colors = ["Red", "Blue", "Pink", "Yellow", "Green", "Brown","Black", "Cyan", "White"]
score = 0
timeLeft = 30
def begin(event):
if timeLeft == 30:
countdown()
nextColor()
def countdown():
global timeLeft
if timeLeft == 0:
messagebox.showinfo("TIME OUT", "Time is over!!\nYour Score: " + str(score))
if timeLeft > 0:
timeLeft -= 1
timeLabel.config(text = "Time Left: %s"%str(timeLeft))
timeLabel.after(1000, countdown)
def nextColor():
global score
global timeLeft
if timeLeft > 0:
e.focus_set()
if e.get().lower().strip() == colors[1].lower(): # Red == red, RED, rEd
score += 1
e.delete(0, END)
random.shuffle(colors)
label.config(bg = 'khaki', fg = str(colors[1]), text = str(colors[0]), padx = 15)
scoreLabel.config(text = "Your Score: %s"%str(score))
def name():
# e1.delete(0, END)
x = e1.get()
messagebox.showinfo("Welcome Message", " ☙ WELCOME TO CG Pro, " + x + " ☙")
# To clear the default text, when you click on the entry field
def clear_search(event):
e1.delete(0, END)
root = Tk()
root.title("CG Pro")
# Width x Height
root.geometry("650x500")
# root.resizable(0, 0)
root.minsize(325, 400)
# root.maxsize(975, 450)
# to change color of entire window
root.configure(bg = "peach puff")
# ENTER PLAYER INFO
e1 = Entry(root, bd = 3, bg = 'linen', fg = 'coral', font = ("comic sans ms", 10, "italic"), relief = SUNKEN)
e1.insert(0, "Enter your Name here...")
e1.pack()
e1.bind("<Button-1>", clear_search) # Vanish default text, once game is done
# Submit info button
frame = Frame(root, borderwidth = 4, bg = "red")
frame.pack()
button = Button(frame, fg = "yellow", bg = "green", text = "Enter Player Info", command = name, font = ("Comic sans ms", 10, 'bold'), activebackground = "pink", activeforeground = "black", height = 1)
button.pack()
# Instructions text
instructions = Label(root, text = '''*****INSTRUCTIONS*****
• A Text will be displayed in a specific color.
• You have to print the COLOR of the text (Not the text itself)''', fg = 'brown', bg = "yellow", font = ("monotype corsiva", 16), padx = 20, pady = 20,
borderwidth = 5, relief = RAISED)
instructions.pack(fill = X)
# Score Counter
scoreLabel = Label(root, text = "Press Enter to START", fg = 'magenta', bg = "pink", font = ("monotype corsiva", 20, 'bold'),padx = 20, borderwidth = 5, relief = RAISED)
scoreLabel.pack()
# Time left (TIMER)
timeLabel = Label(root, text = "Time Left: %s"%str(timeLeft),fg = 'blue', bg = "cyan", font = ("monotype corsiva", 18), borderwidth = 5, relief = RAISED)
timeLabel.pack(side = BOTTOM)
label = Label(root, text='', bg='peach puff', font = ("monotype corsiva", 60))
label.pack()
# Entry field for Answer
e = Entry(root, bd = 5, bg = 'linen', fg = 'coral', font = ("comic sans ms", 20, "italic"), relief = SUNKEN) # use font size, or use width = "any size"
e.insert(0, "Write here...") # DEFAULT TEXT
root.bind('<Return>', begin)
e.pack()
e.focus_set()
root.mainloop()