-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
247 lines (204 loc) · 9.19 KB
/
main.py
File metadata and controls
247 lines (204 loc) · 9.19 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
'''
Simple Code Checker
v0.1 (07-01-2021) By Ruben Plugge aka ByteBitten
Python 3.9.1
'''
from tkinter import *
import configparser
import screeninfo
#####
# Load config
config = configparser.ConfigParser()
config.read('config.ini')
#####
# Variables
selectedMonitor = int(config['MAIN']['DisplayMonitor'])
code_check = 0
codeLength = int(config['MAIN']['CodeLength'])
#####
# System
root = Tk()
root.title('Code Verifier')
root.iconbitmap('Assets/icon.ico')
root.bind(config['MAIN']['QuitKey'],lambda e: root.quit())
# Read monitor-specs for multi-monitor
monitors = []
for m in screeninfo.get_monitors():
monitors.append(['monitor', m.x, m.y, m.width, m.height, m.name])
zerox = int(monitors[selectedMonitor][1])
zeroy = int(monitors[selectedMonitor][2])
monwidth = int(monitors[selectedMonitor][3])
monheight = int(monitors[selectedMonitor][4])
location = "{}x{}+{}+{}".format(monwidth, monheight, zerox, zeroy)
root.geometry(location)
root.overrideredirect(True)
#####
# Functions
# Input limiter function (WIP)
def num_limit(p, this_field):
global codeLength
if p == "":
return True
else:
print("Entry" + this_field + ": " + p)
this_field = int(this_field)
entries = [entry1, entry2, entry3, entry4, entry5, entry6]
if this_field < codeLength:
next_field = entries[this_field]
# Check if it's a number
if p.isdigit():
if this_field < codeLength:
# Set focus on next field
next_field.focus_set()
else:
root.after(100, code_checker)
return True
else:
# Check if it's Backspace or del/home/end/PgUp/PgDn
if p != "\x08" and p != "":
print("Entry" + this_field + ": " + p)
return False
else:
if this_field < codeLength:
next_field.focus_set()
else:
return True
def code_checker():
global code_check
global codeLength
enteredCode = ''
enteredCode += entry1.get()
enteredCode += entry2.get()
enteredCode += entry3.get()
if codeLength == 3:
if enteredCode in config['3codes']['list']:
code_check = 1
else:
code_check = 2
if codeLength == 4:
enteredCode += entry4.get()
if enteredCode in config['4codes']['list']:
code_check = 1
else:
code_check = 2
if codeLength == 5:
enteredCode += entry4.get()
enteredCode += entry5.get()
if enteredCode in config['5codes']['list']:
code_check = 1
else:
code_check = 2
if codeLength == 6:
enteredCode += entry4.get()
enteredCode += entry5.get()
enteredCode += entry6.get()
if enteredCode in config['6codes']['list']:
code_check = 1
else:
code_check = 2
show_result()
def show_result():
global code_check
print("== Show Result ==")
print(code_check)
# If code is correct
if code_check == 1:
# Image code accepted
main_canvas.itemconfig(imgbg, image = codeAccepted)
# If code is wrong
elif code_check == 2:
# Image code denied
main_canvas.itemconfig(imgbg, image = codeDenied)
# Clear fields
entry1.delete(0, END)
entry2.delete(0, END)
entry3.delete(0, END)
entry4.delete(0, END)
entry5.delete(0, END)
entry6.delete(0, END)
# Set focus to first field
entry1.focus_set()
#main_canvas.after(1000, main_canvas.itemconfig(imgbg, image = background))
else:
pass
#####
# Screen items
# Load images
background = PhotoImage(file='Assets/background.png')
companyLogo = PhotoImage(file='Assets/company_logo.png')
codeDenied = PhotoImage(file='Assets/redbg.png')
codeAccepted = PhotoImage(file='Assets/greenbg.png')
# Set fullscreen canvas
main_canvas = Canvas(root, bg="#000000", bd=0, highlightthickness=0)
main_canvas.pack(fill="both", expand=True)
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
# Set background image in canvas
imgbg = main_canvas.create_image(monwidth/2, height/2, image=background)
imgbg
# Company logo
imglogo = main_canvas.create_image(monwidth/2, 100, anchor=N, image=companyLogo)
imglogo
# Top text
imgtoptext = main_canvas.create_text(monwidth/2, 375, anchor=N, text=config['TopText']['Text'], font=(config['TopText']['FontType'], config['TopText']['FontSize']), fill=config['TopText']['FontColor'])
imgtoptext
# Input num limiter command
vcmd = root.register(func=num_limit)
# 3-6 single-digit input fields
entry1 = Entry(root, validate='key', validatecommand=(vcmd, '%P', 1), font=(config['EntryFields']['FontType'], config['EntryFields']['FontSize']), fg=config['EntryFields']['FontColor'], bg=config['EntryFields']['BGColor'], width=config['EntryFields']['Width'], bd=0, justify='center')
entry2 = Entry(root, validate='key', validatecommand=(vcmd, '%P', 2), font=(config['EntryFields']['FontType'], config['EntryFields']['FontSize']), fg=config['EntryFields']['FontColor'], bg=config['EntryFields']['BGColor'], width=config['EntryFields']['Width'], bd=0, justify='center')
entry3 = Entry(root, validate='key', validatecommand=(vcmd, '%P', 3), font=(config['EntryFields']['FontType'], config['EntryFields']['FontSize']), fg=config['EntryFields']['FontColor'], bg=config['EntryFields']['BGColor'], width=config['EntryFields']['Width'], bd=0, justify='center')
entry4 = Entry(root, validate='key', validatecommand=(vcmd, '%P', 4), font=(config['EntryFields']['FontType'], config['EntryFields']['FontSize']), fg=config['EntryFields']['FontColor'], bg=config['EntryFields']['BGColor'], width=config['EntryFields']['Width'], bd=0, justify='center')
entry5 = Entry(root, validate='key', validatecommand=(vcmd, '%P', 5), font=(config['EntryFields']['FontType'], config['EntryFields']['FontSize']), fg=config['EntryFields']['FontColor'], bg=config['EntryFields']['BGColor'], width=config['EntryFields']['Width'], bd=0, justify='center')
entry6 = Entry(root, validate='key', validatecommand=(vcmd, '%P', 6), font=(config['EntryFields']['FontType'], config['EntryFields']['FontSize']), fg=config['EntryFields']['FontColor'], bg=config['EntryFields']['BGColor'], width=config['EntryFields']['Width'], bd=0, justify='center')
# Entry position adjust
field1 = -200
field2 = 0
field3 = 200
field4 = 300
field5 = 400
field6 = 500
# Entry placing
if int(codeLength) == 3:
entry_window1 = main_canvas.create_window(monwidth/2+field1, 500, anchor=N, window=entry1)
entry_window2 = main_canvas.create_window(monwidth/2+field2, 500, anchor=N, window=entry2)
entry_window3 = main_canvas.create_window(monwidth/2+field3, 500, anchor=N, window=entry3)
elif int(codeLength) == 4:
field1 = field1-100
field2 = field2-100
field3 = field3-100
entry_window1 = main_canvas.create_window(monwidth/2+field1, 500, anchor=N, window=entry1)
entry_window2 = main_canvas.create_window(monwidth/2+field2, 500, anchor=N, window=entry2)
entry_window3 = main_canvas.create_window(monwidth/2+field3, 500, anchor=N, window=entry3)
entry_window4 = main_canvas.create_window(monwidth/2+field4, 500, anchor=N, window=entry4)
elif int(codeLength) == 5:
field1 = field1-200
field2 = field2-200
field3 = field3-200
field4 = field4-100
entry_window1 = main_canvas.create_window(monwidth/2+field1, 500, anchor=N, window=entry1)
entry_window2 = main_canvas.create_window(monwidth/2+field2, 500, anchor=N, window=entry2)
entry_window3 = main_canvas.create_window(monwidth/2+field3, 500, anchor=N, window=entry3)
entry_window4 = main_canvas.create_window(monwidth/2+field4, 500, anchor=N, window=entry4)
entry_window5 = main_canvas.create_window(monwidth/2+field5, 500, anchor=N, window=entry5)
elif int(codeLength) == 6:
field1 = field1-300
field2 = field2-300
field3 = field3-300
field4 = field4-200
field5 = field5-100
entry_window1 = main_canvas.create_window(monwidth/2+field1, 500, anchor=N, window=entry1)
entry_window2 = main_canvas.create_window(monwidth/2+field2, 500, anchor=N, window=entry2)
entry_window3 = main_canvas.create_window(monwidth/2+field3, 500, anchor=N, window=entry3)
entry_window4 = main_canvas.create_window(monwidth/2+field4, 500, anchor=N, window=entry4)
entry_window5 = main_canvas.create_window(monwidth/2+field5, 500, anchor=N, window=entry5)
entry_window6 = main_canvas.create_window(monwidth/2+field6, 500, anchor=N, window=entry6)
else:
pass
entry1.focus_set()
# Instructions text
main_canvas.create_text(monwidth/2, 700, anchor=N, text=config['InstructionText']['Text'], font=(config['InstructionText']['FontType'], config['InstructionText']['FontSize']), fill=config['InstructionText']['FontColor'])
# Bottom text
main_canvas.create_text(monwidth/2, 1025, anchor=N, text=config['BottomText']['Text'], font=(config['BottomText']['FontType'], config['BottomText']['FontSize']), fill=config['BottomText']['FontColor'])
#####
root.mainloop()