-
Notifications
You must be signed in to change notification settings - Fork 0
/
guiNumberGuess.py
66 lines (53 loc) · 1.85 KB
/
guiNumberGuess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from logging import root
from string import whitespace
from tkinter import*
import time
import random
root = Tk()
root.title("Guess the number")
root.geometry("500x500")
num_label = Label(root, text = "3 Tries to guess a number\nBetween 1 and 10", font=("Brush Script MT", 24))
num_label.pack(pady=20)
def guesser():
if guess_box.get().isdigit():
global tries
tries = tries -1
if tries != 0:
# label reset
num_label.config(text="Pick a number\nBetween 1 and 10")
diff = abs(num - int(guess_box.get()))
if (int(guess_box.get())==num):
bc = "SystemButtonFace"
num_label.config(text="Correct!")
elif diff == 5:
bc = "white"
elif diff < 5:
bc = f"#ff{diff}{diff}{diff}{diff}"
else:
bc = f"#{diff}{diff}{diff}{diff}ff"
root.config(bg=bc)
num_label.config(bg = bc)
else:
guess_box.delete(0,END)
num_label.config(text="Out of tries!")
time.sleep(2)
rando()
else:
guess_box.delete(0,END)
num_label.config(text="Please enter a number!")
def rando():
global num
global tries
tries = 3
num = random.randint(1,10)
guess_box.delete(0,END)
num_label.config(bg = "SystemButtonFace" , text = "3 Tries to guess a number\nBetween 1 and 10", font=("Brush Script MT", 24))
root.config(bg = "SystemButtonFace")
guess_box = Entry(root, font = ("Helvetica", 100), width=2)
guess_box.pack(pady=20)
guess_button = Button(root, text = "Submit", command=guesser)
guess_button.pack(pady=20)
rand_button = Button(root, text = "New Number", command=rando)
rand_button.pack(pady=20)
rando()
root.mainloop()