-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuessNumber.py
102 lines (85 loc) · 1.81 KB
/
GuessNumber.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import tkinter
from tkinter import *
import random
from tkinter import messagebox
# you can add more words as per your requirement
Answers = [
"3",
"8",
"2",
"0",
"0",
"0",
"1",
]
Numbers = [
"5+1_=18",
"6+1_+13=37",
"5+1_+2=19",
"1_+6+13=29",
"8+15+1_=30",
"2_+17=37",
"1_+19=30" ,
]
# I have improvised the code by using len(words)
num = random.randrange(0, len(Numbers), 1)
def default():
global Numbers,Answers,num
lbl.config(text = Numbers[num])
def res():
global Numbers,Answers,num
num = random.randrange(0, len(Numbers), 1)
lbl.config(text = Numbers[num])
point.delete(0, END)
def checkAnswer():
global Numbers, Answers,num
var = point.get()
if var == Answers[num]:
messagebox.showinfo("Success", "Answer is Correct")
res()
else:
messagebox.showerror("Error", "incorrect")
point.delete(0, END)
root = tkinter.Tk()
root.geometry("550x400+400+500")
root.title("Guess Numbers")
root.configure(background = "#2C3335")
lbl = Label(
root,
text = "Start",
font = ("Roboto", 18),
bg = "#4C4B4B",
fg = "White",
)
lbl.pack(pady = 30,ipady=10,ipadx=10)
ans1 = StringVar()
point = Entry(
root,
font = ("Roboto", 16),
textvariable = ans1,
)
point.pack(ipady=5,ipadx=5)
btncheck = Button(
root,
text = "Check",
font = ("Roboto Bold", 16),
width = 16,
bg = "#2F363F",
fg = "White",
relief = GROOVE,
command = checkAnswer,
)
btncheck.pack(pady = 40)
btnreset = Button(
root,
text = "Reset",
font = ("Roboto", 16),
width = 16,
bg = "#4c4b4b",
fg = "#EA425C",
relief = GROOVE,
command = res,
)
btnreset.pack()
default()
root.mainloop()