-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (60 loc) · 1.81 KB
/
main.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
import ctypes
import random
import time
import tkinter as tk
#################################################
# Program that prompts user every hour to answer a math question and locks the computer if incorrect 5 times or no answer
# Good for kids to learn math.
# Requires python3 and windows
#################################################
attempt=0
while 1:
#if 1:
#ask question before anything starts
correct = False
attempt=0
a = random.randint(10,99)
b = random.randint(10,99)
c = random.randint(10,99)
correct_answer = (a+b)-c
window = tk.Tk()
greeting = tk.Label(text="Answer this correctly or PC will be locked. You have 5 attempts and 5 minutes\n( "+str(a)+" + "+str(b)+" ) - "+str(c)+" = ?")
window.after(300000,lambda:window.destroy())
greeting.pack()
entry = tk.Entry()
def check_submit(event=None):
global attempt
global correct_answer
global correct
#these are for debugging
#print(str(correct_answer))
#print(str(attempt))
answer = entry.get()
if str(correct_answer) == answer:
correct = True
else:
attempt+=1
if attempt > 5 or correct:
window.destroy()
attempt=0
entry.bind('<Return>', check_submit)
entry.pack()
submit = tk.Button(text="Submit",command=check_submit)
submit.pack()
window.mainloop()
if not correct:
answer_window = tk.Tk()
label = tk.Label(text="Correct answer is "+str(correct_answer)+"\nThis will now lock in 5 seconds.")
label.pack()
answer_window.after(7000,lambda:answer_window.destroy())
answer_window.mainloop()
#lock windows
ctypes.windll.user32.LockWorkStation()
else:
answer_window = tk.Tk()
label = tk.Label(text="Thats corect! This window will close in 10 seconds.")
label.pack()
answer_window.after(10000,lambda:answer_window.destroy())
answer_window.mainloop()
#wait sleep for an hour
time.sleep(3600)