Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 50_letters_game.py
- from Tkinter import *
- from random import randint
- import time, string
- keyLt = 0
- score = 0
- c = 50
- def init():
- btnStart["state"] = DISABLED
- time.sleep(1)
- root.bind("<Key>", keyEntry)
- go()
- def keyEntry(event):
- global keyLt, score
- oLetter = event.char.upper()
- if oLetter == keyLt:
- print("Excellent!")
- score = score + 25
- else:
- print("Whoops!")
- score = score - 1
- def go():
- global keyLt, c
- tactic = list(string.ascii_uppercase)
- newLt = randint(0, len(tactic) - 1)
- keyLt = tactic[newLt]
- keyLb["text"] = keyLt
- if c:
- lbl["text"] = "Score: " + str(score)
- c-=1
- root.after(1000, go)
- else:
- keyLb.config(font=("ariel", 48))
- keyLb.place(x=50, y=100)
- keyLb["text"] = 'GAME OVER'
- root = Tk()
- root.geometry("500x500")
- keyLb = Label(root, text="A")
- keyLb.config(font=("ariel", 100))
- keyLb.place(x=220, y=100)
- lbl = Label(root, text="Score: 0")
- lbl.config(font=("ariel", 20))
- lbl.place(x=50, y=400)
- btnStart = Button(root, text="START", font=25,
- height=1, width=7, command=init)
- btnStart.place(x=220, y=450)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement