# import the modulesimporttkinterimportrandom# list of possible colour.colours=['Red','Blue','Green','Pink','Black','Yellow','Orange','White','Purple','Brown']score=0# the game time left, initially 30 seconds.timeleft=30# function that will start the game.defstartGame(event):iftimeleft==30:# start the countdown timer.countdown()# run the function to# choose the next colour.nextColour()# Function to choose and# display the next colour.defnextColour():# use the globally declared 'score'# and 'play' variables above.globalscoreglobaltimeleft# if a game is currently in playiftimeleft>0:# make the text entry box active.e.focus_set()# if the colour typed is equal# to the colour of the textife.get().lower()==colours[1].lower():score+=1# clear the text entry box.e.delete(0,tkinter.END)random.shuffle(colours)# change the colour to type, by changing the# text _and_ the colour to a random colour valuelabel.config(fg=str(colours[1]),text=str(colours[0]))# update the score.scoreLabel.config(text="Score: "+str(score))# Countdown timer functiondefcountdown():globaltimeleft# if a game is in playiftimeleft>0:# decrement the timer.timeleft-=1# update the time left labeltimeLabel.config(text="Time left: "+str(timeleft))# run the function again after 1 second.timeLabel.after(1000,countdown)# Driver Code# create a GUI windowroot=tkinter.Tk()# set the titleroot.title("COLORGAME")# set the sizeroot.geometry("375x200")# add an instructions labelinstructions=tkinter.Label(root,text="Type in the colour""of the words, and not the word text!",font=('Helvetica',12))instructions.pack()# add a score labelscoreLabel=tkinter.Label(root,text="Press enter to start",font=('Helvetica',12))scoreLabel.pack()# add a time left labeltimeLabel=tkinter.Label(root,text="Time left: "+str(timeleft),font=('Helvetica',12))timeLabel.pack()# add a label for displaying the colourslabel=tkinter.Label(root,font=('Helvetica',60))label.pack()# add a text entry box for# typing in colourse=tkinter.Entry(root)# run the 'startGame' function# when the enter key is pressedroot.bind('<Return>',startGame)e.pack()# set focus on the entry boxe.focus_set()# start the GUIroot.mainloop()