-
Notifications
You must be signed in to change notification settings - Fork 1
/
c1.py
45 lines (26 loc) · 949 Bytes
/
c1.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
import tkinter as tk
import random
guessesTaken = 0
number = random.randint(1,20)
def check():
while guessesTaken < 6:
guess = int(txt_guess.get())
if guess < number:
msg = ('Your guess is too low.')
elif guess > number:
msg = ('Your guess is too high.')
elif guess == number:
msg = ('Good job!')
lbl_result["text"] = msg
root = tk.Tk()
lbl_title = tk.Label(root,text="Welcome to the Guessing Game! I am thinking of a number between 1 and 100.")
lbl_title.pack()
lbl_result = tk.Label(root,text="Good luck!")
lbl_result.pack()
btn_check = tk.Button(root,text="Check", fg = "blue", command = check)
btn_check.pack(side = "left")
btn_reset = tk.Button(root,text="Reset", fg = "red", command = root.quit())
btn_reset.pack(side = "right")
txt_guess = tk.Entry(root, width = 10)
txt_guess.pack()
root.mainloop()