Skip to content

Commit 2b25d54

Browse files
committed
Adding Color_Guess GUI
1 parent 7d76916 commit 2b25d54

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

Diff for: Color Guess-GUI/Color_guess.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import random
2+
import tkinter
3+
4+
colors_name = ['Red', 'White', 'Yellow', 'Pink',
5+
'Blue', 'Black', 'Brown', 'Purple', 'Green', 'Cyan']
6+
score = 0
7+
time_left = 60
8+
9+
10+
def start_game(play):
11+
if time_left == 60:
12+
countdown()
13+
change_color()
14+
15+
16+
def change_color():
17+
global score
18+
global time_left
19+
if (time_left > 0):
20+
e.focus_set()
21+
if e.get().lower() == colors_name[1].lower():
22+
score += 1
23+
24+
e.delete(0, tkinter.END)
25+
random.shuffle(colors_name)
26+
label.config(fg=str(colors_name[1]), text=str(colors_name[0]))
27+
scoreLabel.config(text="Score: "+str(score))
28+
29+
30+
def countdown():
31+
global time_left
32+
if time_left > 0:
33+
time_left -= 1
34+
timeLabel.config(text='Time Left: '+str(time_left))
35+
timeLabel.after(1000, countdown)
36+
37+
38+
root = tkinter.Tk()
39+
root.title("The ColorGuess")
40+
root.geometry("600x400")
41+
42+
instruct = tkinter.Label(root, text="Which Color?", font=("san-serif", 30))
43+
instruct.pack()
44+
45+
scoreLabel = tkinter.Label(
46+
root, text="Press Enter to Start", font=("san-serif", 24))
47+
scoreLabel.pack()
48+
49+
timeLabel = tkinter.Label(root, text="Time Left: " +
50+
str(time_left), font=("san-serif", 18))
51+
timeLabel.pack()
52+
53+
label = tkinter.Label(root, font=("san-serif", 60))
54+
label.pack()
55+
56+
e = tkinter.Entry(root)
57+
root.bind('<Return>', start_game)
58+
e.pack()
59+
e.focus_set()
60+
61+
root.mainloop()

Diff for: Color Guess-GUI/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Color Guessing Game GUI
2+
3+
Using this script you can setup and play a game in whihc you are supposed to guess the color in which the word is displayed in.
4+
5+
## Dependancies
6+
7+
You will use `Tkinter` and `random` python module.
8+
9+
## Setup Instructions
10+
11+
In order to run this script, you need to have any kind of python compiler and interpreter installed on your system. (Ex: VSCode or pycharm)
12+
13+
## Sample Output
14+
15+
On running `Color_guess.py`.
16+
![Score_time](Score_time.jpg)
17+
18+
![Score](Score.jpg)
19+
20+
## Author
21+
22+
[Varsha Nimmagadda](https://github.com/varshanim)

Diff for: Color Guess-GUI/Score.jpg

53.1 KB
Loading

Diff for: Color Guess-GUI/Score_time.jpg

52.3 KB
Loading

0 commit comments

Comments
 (0)