Juego del Color -Tkinter- Python

#Programa que realiza un pequeño juego utilizando Tkinter en Python.

# import the modulesfrom  Tkinter import *
import random


colours = ['Red', 'Blue', 'Green', 'Pink', 'Black','Yellow', 'Orange', 'White', 'Purple', 
'Brown']
score = 0

timeleft = 30


def startGame(event):
    if timeleft == 30:
        
        countdown()

    nextColour()


def nextColour():
    
    global score
    global timeleft

    if timeleft > 0:

        
        e.focus_set()

        
        if e.get().lower() == colours[1].lower():
            score += 1.        e.delete(0, END)

        random.shuffle(colours)

        
        label.config(fg=str(colours[1]), text=str(colours[0]))

        # update the score.     scoreLabel.config(text="Score: " + str(score))


# Countdown timer functiondef countdown():
    global timeleft

    
    if timeleft > 0:
        
        timeleft -= 1
        
        timeLabel.config(text="Tiempo restante: " + str(timeleft))

       .        timeLabel.after(1000, countdown)


# Driver Code

root = Tk()


root.title("COLORGAME")


root.geometry("375x200")


instructions = Label(root, text="escriba el color" "de la palabra, y no la palabra!", 
font=('Helvetica', 12))
instructions.pack()


scoreLabel = Label(root, text="Presione enter para iniciar", font=('Helvetica', 12))
scoreLabel.pack()


timeLabel = Label(root, text="Tiempo restante: " +
                                     str(timeleft), font=('Helvetica', 12))

timeLabel.pack()

label = Label(root, font=('Helvetica', 60))
label.pack()

e = Entry(root)


root.bind('<Return>', startGame)
e.pack()

e.focus_set()

root.mainloop()



No hay comentarios:

Publicar un comentario