Advertisement
here2share

# 50_letters_game.py

Aug 1st, 2017
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. # 50_letters_game.py
  2.  
  3. from Tkinter import *
  4. from random import randint
  5. import time, string
  6.  
  7. keyLt = 0
  8. score = 0
  9. c = 50
  10.  
  11. def init():
  12.     btnStart["state"] = DISABLED
  13.     time.sleep(1)
  14.     root.bind("<Key>", keyEntry)
  15.     go()
  16.  
  17. def keyEntry(event):
  18.     global keyLt, score
  19.     oLetter = event.char.upper()
  20.  
  21.     if oLetter == keyLt:
  22.         print("Excellent!")
  23.         score = score + 25
  24.     else:
  25.         print("Whoops!")
  26.         score = score - 1
  27.  
  28.  
  29. def go():
  30.     global keyLt, c
  31.     tactic = list(string.ascii_uppercase)
  32.     newLt = randint(0, len(tactic) - 1)
  33.     keyLt = tactic[newLt]
  34.     keyLb["text"] = keyLt
  35.    
  36.     if c:
  37.         lbl["text"] = "Score: " + str(score)
  38.         c-=1
  39.         root.after(1000, go)
  40.     else:
  41.         keyLb.config(font=("ariel", 48))
  42.         keyLb.place(x=50, y=100)
  43.         keyLb["text"] = 'GAME OVER'
  44.  
  45.  
  46. root = Tk()
  47. root.geometry("500x500")
  48.  
  49. keyLb = Label(root, text="A")
  50. keyLb.config(font=("ariel", 100))
  51. keyLb.place(x=220, y=100)
  52.  
  53.  
  54. lbl = Label(root, text="Score: 0")
  55. lbl.config(font=("ariel", 20))
  56. lbl.place(x=50, y=400)
  57.  
  58. btnStart = Button(root, text="START", font=25,
  59.     height=1, width=7, command=init)
  60. btnStart.place(x=220, y=450)
  61.  
  62. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement