Amazing-Python-Scripts
61 строка · 1.4 Кб
1import random2import tkinter3
4colors_name = ['Red', 'White', 'Yellow', 'Pink',5'Blue', 'Black', 'Brown', 'Purple', 'Green', 'Cyan']6score = 07time_left = 608
9
10def start_game(play):11if time_left == 60:12countdown()13change_color()14
15
16def change_color():17global score18global time_left19if (time_left > 0):20e.focus_set()21if e.get().lower() == colors_name[1].lower():22score += 123
24e.delete(0, tkinter.END)25random.shuffle(colors_name)26label.config(fg=str(colors_name[1]), text=str(colors_name[0]))27scoreLabel.config(text="Score: "+str(score))28
29
30def countdown():31global time_left32if time_left > 0:33time_left -= 134timeLabel.config(text='Time Left: '+str(time_left))35timeLabel.after(1000, countdown)36
37
38root = tkinter.Tk()39root.title("The ColorGuess")40root.geometry("600x400")41
42instruct = tkinter.Label(root, text="Which Color?", font=("san-serif", 30))43instruct.pack()44
45scoreLabel = tkinter.Label(46root, text="Press Enter to Start", font=("san-serif", 24))47scoreLabel.pack()48
49timeLabel = tkinter.Label(root, text="Time Left: " +50str(time_left), font=("san-serif", 18))51timeLabel.pack()52
53label = tkinter.Label(root, font=("san-serif", 60))54label.pack()55
56e = tkinter.Entry(root)57root.bind('<Return>', start_game)58e.pack()59e.focus_set()60
61root.mainloop()62