Advertisement
here2share

# color_game.py

Nov 2nd, 2019
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. # color_game.py
  2.  
  3. import random
  4. import Tkinter
  5.  
  6. my_colors = ['RED', 'GREEN', 'YELLOW', 'BLUE', 'ORANGE', 'BLACK', 'WHITE', 'PURPLE', 'PINK']
  7. score = 0
  8. time = 60
  9.  
  10. def color_game(event):
  11.     if time == 60:
  12.         countdown()
  13.  
  14.     nextColor()
  15.  
  16.  
  17. def nextColor():
  18.     global score
  19.     global time
  20.  
  21.     if time > 0:
  22.         e.focus_set()
  23.  
  24.         if e.get().lower() == my_colors[1].lower():
  25.             score += 1
  26.  
  27.         e.delete(0, Tkinter.END)
  28.         random.shuffle(my_colors)
  29.  
  30.         label.config(fg=str(my_colors[1]), text=str(my_colors[0]))
  31.  
  32.         scoreLabel.config(text="Score: " + str(score))
  33.  
  34.  
  35. def countdown():
  36.     global time
  37.  
  38.     if time > 0:
  39.         time -= 1
  40.  
  41.         timeLabel.config(text="Time Left: " + str(time))
  42.  
  43.         timeLabel.after(1000, countdown)
  44.  
  45.  
  46. root = Tkinter.Tk()
  47.  
  48. root.title("COLOR GAME")
  49.  
  50. root.geometry("375x200")
  51.  
  52. instructions = Tkinter.Label(root, text="Type In The Color Of The Words, Not The Text Word!", font=('Helvetica', 12))
  53. instructions.pack()
  54.  
  55. scoreLabel = Tkinter.Label(root, text="Press Enter To Start", font=('Helvetica', 12))
  56. scoreLabel.pack()
  57.  
  58. timeLabel = Tkinter.Label(root, text="Time Left: " + str(time), font=('Helvetica', 12))
  59.  
  60. timeLabel.pack()
  61.  
  62. label = Tkinter.Label(root, font=('Helvetica', 60))
  63. label.pack()
  64.  
  65. e = Tkinter.Entry(root)
  66.  
  67. root.bind('<Return>', color_game)
  68. e.pack()
  69.  
  70. e.focus_set()
  71.  
  72. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement