Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # color_game.py
- import random
- import Tkinter
- my_colors = ['RED', 'GREEN', 'YELLOW', 'BLUE', 'ORANGE', 'BLACK', 'WHITE', 'PURPLE', 'PINK']
- score = 0
- time = 60
- def color_game(event):
- if time == 60:
- countdown()
- nextColor()
- def nextColor():
- global score
- global time
- if time > 0:
- e.focus_set()
- if e.get().lower() == my_colors[1].lower():
- score += 1
- e.delete(0, Tkinter.END)
- random.shuffle(my_colors)
- label.config(fg=str(my_colors[1]), text=str(my_colors[0]))
- scoreLabel.config(text="Score: " + str(score))
- def countdown():
- global time
- if time > 0:
- time -= 1
- timeLabel.config(text="Time Left: " + str(time))
- timeLabel.after(1000, countdown)
- root = Tkinter.Tk()
- root.title("COLOR GAME")
- root.geometry("375x200")
- instructions = Tkinter.Label(root, text="Type In The Color Of The Words, Not The Text Word!", 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(time), font=('Helvetica', 12))
- timeLabel.pack()
- label = Tkinter.Label(root, font=('Helvetica', 60))
- label.pack()
- e = Tkinter.Entry(root)
- root.bind('<Return>', color_game)
- e.pack()
- e.focus_set()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement