Amazing-Python-Scripts

Форк
0
61 строка · 1.4 Кб
1
import random
2
import tkinter
3

4
colors_name = ['Red', 'White', 'Yellow', 'Pink',
5
               'Blue', 'Black', 'Brown', 'Purple', 'Green', 'Cyan']
6
score = 0
7
time_left = 60
8

9

10
def start_game(play):
11
    if time_left == 60:
12
        countdown()
13
    change_color()
14

15

16
def change_color():
17
    global score
18
    global time_left
19
    if (time_left > 0):
20
        e.focus_set()
21
        if e.get().lower() == colors_name[1].lower():
22
            score += 1
23

24
        e.delete(0, tkinter.END)
25
        random.shuffle(colors_name)
26
        label.config(fg=str(colors_name[1]), text=str(colors_name[0]))
27
        scoreLabel.config(text="Score: "+str(score))
28

29

30
def countdown():
31
    global time_left
32
    if time_left > 0:
33
        time_left -= 1
34
        timeLabel.config(text='Time Left: '+str(time_left))
35
        timeLabel.after(1000, countdown)
36

37

38
root = tkinter.Tk()
39
root.title("The ColorGuess")
40
root.geometry("600x400")
41

42
instruct = tkinter.Label(root, text="Which Color?", font=("san-serif", 30))
43
instruct.pack()
44

45
scoreLabel = tkinter.Label(
46
    root, text="Press Enter to Start", font=("san-serif", 24))
47
scoreLabel.pack()
48

49
timeLabel = tkinter.Label(root, text="Time Left: " +
50
                          str(time_left), font=("san-serif", 18))
51
timeLabel.pack()
52

53
label = tkinter.Label(root, font=("san-serif", 60))
54
label.pack()
55

56
e = tkinter.Entry(root)
57
root.bind('<Return>', start_game)
58
e.pack()
59
e.focus_set()
60

61
root.mainloop()
62

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.