-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguessme.py
52 lines (37 loc) · 1.38 KB
/
guessme.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
import tkinter as tk
from tkinter import *
from tkinter import messagebox
import random
def main():
root = tk.Tk()
root.title('Guess Me')
root.geometry('400x300')
num = random.randint(1,10)
global attempts
attempts = 3
def check_ans():
global attempts
attempts -= 1
guess = int(num_entry.get())
if num == guess:
label_win = Label(root,text="--> You win Congrats!").pack()
btn_check.pack_forget()
elif attempts == 0:
label_out = Label(root,text="--> You are out of attempts!").pack()
btn_check.pack_forget()
elif guess < num:
label_big = Label(root,text="--> I am Bigger than your guess!"+f" {attempts} attempts are left").pack()
elif guess > num:
label_small = Label(root,text = "--> I am smaller than your guess! "+f" {attempts} attempts are left").pack()
def quit():
root.destroy()
label = Label(root,text = "I am a number Between 1 to 10", fg = 'white',bg = 'teal')
label.pack()
num_entry = Entry(root, bd = 5, width = 40)
num_entry.pack()
btn_check = Button(root,text = "Check",command = check_ans,bg = 'Black',activebackground='light blue',fg = 'white')
btn_check.pack()
btn_quit = Button(root,text = "Quit",command = quit,activebackground='light blue',bg = 'Black',fg = 'white')
btn_quit.pack()
label_at = Label(root,text = f'You have 3 attempts to guess me').pack()
root.mainloop()