-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemoKid.py
2741 lines (2311 loc) · 96.8 KB
/
MemoKid.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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from datetime import datetime
import tkinter as tk
import pygame as pg
from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk
import sqlite3
import random
from tkinter import messagebox
import threading
import time
# connect to db
sqlconnect = sqlite3.connect('MemoKidDB.db', check_same_thread=False)
cursor = sqlconnect.cursor()
sqlconnect2 = sqlite3.connect('usergrades.db', check_same_thread=False)
cursorgrades = sqlconnect2.cursor()
# Create the screen
root = tk.Tk()
root.geometry("1280x720")
root.title("MemoKid")
# background image
C = Canvas(root, bg="blue", height=1280, width=720)
bg = PhotoImage(file="bg.png")
background_label = Label(root, image=bg)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
C.pack()
# subfunction to display title image
def TitleImage():
title1 = Image.open("Title1.png")
title = ImageTk.PhotoImage(title1)
label_title = tk.Label(image=title)
label_title.image = title
label_title.place(x=400, y=100)
# Function for stat page
def StartPage():
# press on continue go to login page
def ContinueButton():
# clear screen
continuebutton.destroy()
label_startimage.destroy()
LoginPage()
# Loadup startup image
startimage1 = Image.open("StartImage.png")
startimage = ImageTk.PhotoImage(startimage1)
label_startimage = tk.Label(image=startimage)
label_startimage.image = startimage
label_startimage.place(x=400, y=100)
# Continue button
continuebutton = tk.Button(root, text="התחל", command=ContinueButton)
continuebutton.place(x=580, y=500, width=75)
# Function for Login Page
def LoginPage():
TitleImage()
text = None
label_Message = tk.Label(root, bg='#17331b', fg='white', text="")
# function for login button, displayes name if login successful (for now)
def LoginButton():
# save userID and password
user = ID.get()
pw = password.get()
# search for user in db
sql_select_query = "SELECT password FROM userslist WHERE id =?"
idlist = (user,)
cursor.execute(sql_select_query, idlist)
pwdb = cursor.fetchone()
if (pwdb): # if user was found (any data from password col)
if pw == pwdb[0]: # check if the password entered match db
# clear screen
lblfrstrow.destroy()
ID.destroy()
lblsecrow.destroy()
password.destroy()
loginbutton.destroy()
signupbutton.destroy()
forgotpwbutton.destroy()
label_Message.destroy()
# Send to user menu
CheckUserType(user)
else:
label_Message['text'] = "סיסמא לא נכונה" # display wrong password if passwords didn't match
label_Message.place(x=550, y=520, width=200)
else:
label_Message['text'] = "משתמש לא קיים" # display nonexistent user if no data was found
label_Message.place(x=550, y=520, width=200)
# display message
# function for signup button
def SignUpButton():
# clear screen
lblfrstrow.destroy()
ID.destroy()
lblsecrow.destroy()
password.destroy()
loginbutton.destroy()
signupbutton.destroy()
forgotpwbutton.destroy()
label_Message.destroy()
# send to signup page
SignUpPage()
# function for forgotPW button
def ForgotPWButton():
# clear screen
lblfrstrow.destroy()
ID.destroy()
lblsecrow.destroy()
password.destroy()
loginbutton.destroy()
signupbutton.destroy()
forgotpwbutton.destroy()
label_Message.destroy()
# send to ForgotPWPage
ForgotPWPage()
# ID TextBox and label
lblfrstrow = tk.Label(root, bg='#17331b', fg='white', text="תעודת זהות", )
lblfrstrow.place(x=650, y=300)
ID = tk.Entry(root, width=35)
ID.place(x=550, y=300, width=100)
# PW TextBox and label
lblsecrow = tk.Label(root, bg='#17331b', fg='white', text="סיסמה")
lblsecrow.place(x=650, y=350)
password = tk.Entry(root, width=35)
password.place(x=550, y=350, width=100)
# Login button
loginbutton = tk.Button(root, text="התחבר", command=LoginButton)
loginbutton.place(x=580, y=400, width=55)
# SignUp button
signupbutton = tk.Button(root, text="הירשם", command=SignUpButton)
signupbutton.place(x=580, y=440, width=55)
# ForgotPW button
forgotpwbutton = tk.Button(root, text="שכחתי סיסמה", command=ForgotPWButton)
forgotpwbutton.place(x=570, y=480, width=80)
def SignUpPage():
# title image
TitleImage()
# function for register button press
def RegisterButton():
# RegisterCompleteButton
def RegisterCompleteButton(): # clear screen and go to login page
registercompletebutton.destroy()
Successlabel.destroy()
LoginPage()
# save data
name_user = Name.get()
ID_user = ID.get()
city_user = City.get()
school_user = School.get()
class_user = ClassVar.get()
gender_user = GenderVar.get()
type_user = TypeVar.get()
question_user = Question.get()
answer_user = Answer.get()
user_password = PasswordFirst.get()
user_password2 = PasswordSecond.get()
sql_select_id = "SELECT id FROM userslist WHERE id = ?"
ID_list = (ID_user,)
cursor.execute(sql_select_id, ID_list)
registered = cursor.fetchone()
if registered:
RetryLabel['text'] = "משתמש קיים"
RetryLabel.place(x=520, y=470, width=200, height=35)
else:
# check if both passwords match (and not empty)
if user_password == user_password2 and len(user_password) > 5 and user_password2:
# clear screen
SignUpLabel1.destroy()
Name.destroy()
SignUpLabel2.destroy()
ID.destroy()
SignUpLabel3.destroy()
City.destroy()
SignUpLabel4.destroy()
School.destroy()
SignUpLabel5.destroy()
Class.destroy()
SignUpLabel6.destroy()
Gender.destroy()
SignUpLabel7.destroy()
PasswordFirst.destroy()
SignUpLabel8.destroy()
PasswordSecond.destroy()
SignupLabel9.destroy()
Type.destroy()
SignUpLabel10.destroy()
Question.destroy()
SignUpLabel11.destroy()
Answer.destroy()
RegisterButton.destroy()
RetryLabel.destroy()
# insert data into db
sql_insert_query = "INSERT INTO userslist VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
val = (
name_user, ID_user, city_user, school_user, gender_user, class_user, type_user, user_password, "0",
question_user, answer_user)
cursor.execute(sql_insert_query, val)
sqlconnect.commit()
# register succesful and button to go to login page
Successlabel = Label(root, bg='#17331b', fg='white', text="ההרשמה הצליחה , אנא התחברו", )
Successlabel.place(x=500, y=300, width=180)
registercompletebutton = tk.Button(root, text="התחבר", command=RegisterCompleteButton)
registercompletebutton.place(x=570, y=350, width=80)
else: # if passwords didn't match place the label (unmatching passwords try again)
RetryLabel['text'] = "סיסמאות לא תקינות, אנא נסה שנית"
RetryLabel.place(x=520, y=470, width=200, height=35)
# Retry Title
RetryLabel = Label(root, bg='#17331b', fg='white', text="")
# Name Title
SignUpLabel1 = Label(root, bg='#17331b', fg='white', text="שם מלא", )
SignUpLabel1.place(x=920, y=300, width=75)
# Name TextBox
Name = tk.Entry(root, width=35)
Name.place(x=800, y=300, width=100)
# ID Title
SignUpLabel2 = Label(root, bg='#17331b', fg='white', text="תעודת זהות", )
SignUpLabel2.place(x=920, y=350, width=75)
# ID TextBox
ID = tk.Entry(root, width=35)
ID.place(x=800, y=350, width=100)
# City Title
SignUpLabel3 = Label(root, bg='#17331b', fg='white', text="עיר מגורים", )
SignUpLabel3.place(x=920, y=400, width=75)
# City TextBox
City = tk.Entry(root, width=35)
City.place(x=800, y=400, width=100)
# School Title
SignUpLabel4 = Label(root, bg='#17331b', fg='white', text="שם בית הספר", )
SignUpLabel4.place(x=920, y=450, width=75)
# School TextBox
School = tk.Entry(root, width=35)
School.place(x=800, y=450, width=100)
# Class Title
SignUpLabel5 = Label(root, bg='#17331b', fg='white', text="כיתה", )
SignUpLabel5.place(x=920, y=500, width=75)
# Class OptionMenu
ClassVar = StringVar(root)
ClassVar.set("א")
Class = tk.OptionMenu(root, ClassVar, "א", "ב", "ג", "ד", "ה", "ו", "לא רלוונטי")
Class.place(x=800, y=500, width=90)
# Gender Title
SignUpLabel6 = Label(root, bg='#17331b', fg='white', text="מין", )
SignUpLabel6.place(x=920, y=550, width=75)
# Gender OptionMenu
GenderVar = StringVar(root)
GenderVar.set("זכר")
Gender = tk.OptionMenu(root, GenderVar, "זכר", "נקבה")
Gender.pack()
Gender.place(x=800, y=550, width=70)
# PasswordFirst Title
SignUpLabel7 = Label(root, bg='#17331b', fg='white', text="סיסמא אישית (לפחות 6 תווים)", )
SignUpLabel7.place(x=520, y=280, width=175, height=35)
# PasswordFirst TextBox
PasswordFirst = tk.Entry(root, width=35)
PasswordFirst.place(x=520, y=320, width=174, height=25)
# PasswordSecond Title
SignUpLabel8 = Label(root, bg='#17331b', fg='white', text="אימות סיסמא", )
SignUpLabel8.place(x=520, y=370, width=175, height=35)
# PasswordSecond TextBox
PasswordSecond = tk.Entry(root, width=35)
PasswordSecond.place(x=520, y=410, width=174)
# Type Title
SignupLabel9 = Label(root, bg='#17331b', fg='white', text="סוג משתמש", )
SignupLabel9.place(x=920, y=250, height=35)
# Type OptionMenu
TypeVar = StringVar(root)
TypeVar.set("תלמיד")
Type = tk.OptionMenu(root, TypeVar, "תלמיד", "מנהל", "חוקר")
Type.pack()
Type.place(x=800, y=250, width=70)
# Question Title
SignUpLabel10 = Label(root, bg='#17331b', fg='white', text="שאלת אבטחה", )
SignUpLabel10.place(x=250, y=280, width=175, height=35)
# Answer TextBox
Question = tk.Entry(root, width=35)
Question.place(x=250, y=320, width=174, height=25)
# Answer Title
SignUpLabel11 = Label(root, bg='#17331b', fg='white', text="תשובת אבטחה", )
SignUpLabel11.place(x=250, y=370, width=175, height=35)
# Answer TextBox
Answer = tk.Entry(root, width=35)
Answer.place(x=250, y=410, width=174)
# Register Button
RegisterButton = tk.Button(root, text="הירשם", command=RegisterButton)
RegisterButton.place(x=580, y=510, width=80, height=25)
# function for ForggotPWPage
def ForgotPWPage():
TitleImage()
label_UserNotFound = tk.Label(root, bg="#17331b", fg='white', text="משתמש לא קיים, נסה שנית")
# function for pressing the button (after entering ID)
def ForgotPWButton():
# function for pressing send button (after answering question)
def SendButton():
# function for return to login button
def returntologin():
# clear screen
returntologinbutton.destroy()
label_PW.destroy()
label_Question.destroy()
label_ID.destroy()
QuestBox.destroy()
sendbutton.destroy()
ID.destroy()
# send to login
LoginPage()
# save answer
answer = QuestBox.get()
# compare answer to db
sql_select_query = "SELECT answer FROM userslist WHERE id =?"
idlist = (userID,)
cursor.execute(sql_select_query, idlist)
answerdb = cursor.fetchone()
if answer == answerdb[0]: # if answers match
sql_select_query = "SELECT password FROM userslist WHERE id =?"
idlist = (userID,)
cursor.execute(sql_select_query, idlist)
pwdb = cursor.fetchone()
text = "סיסמתך היא " + str(pwdb[0]) # save password from db to text variable
else: # if passwords didn't match
text = "תשובה לא נכונה , נסה שנית" # save message to text variable
# lable to display text var (msg or pw)
label_PW['text'] = text
label_PW.update()
label_PW.place(x=550, y=450, width=200)
if text != "תשובה לא נכונה , נסה שנית":
returntologinbutton = tk.Button(root, text="התחבר", command=returntologin)
returntologinbutton.place(x=600, y=500, width=80)
# save data
userID = ID.get()
sql_select_query = "SELECT ID FROM userslist WHERE id =?"
idlist = (userID,)
cursor.execute(sql_select_query, idlist)
iddb = cursor.fetchone()
# if user was found in DB
if iddb:
# clear screen
label_ID.destroy()
ID.destroy()
sendidbutton.destroy()
label_UserNotFound.destroy()
# get question from db
sql_select_query = "SELECT question FROM userslist WHERE id =?"
idlist = (userID,)
cursor.execute(sql_select_query, idlist)
question = cursor.fetchone()
# display question and textbox for answer
label_Question = tk.Label(root, bg='#17331b', fg='white', text=question[0])
label_Question.place(x=550, y=300, width=200)
QuestBox = tk.Entry(root, width=200)
QuestBox.place(x=550, y=350, width=200)
# send button
sendbutton = tk.Button(root, text="שלח", command=SendButton)
sendbutton.place(x=600, y=400, width=75)
else: # user was not found
label_UserNotFound.place(x=550, y=400) # place label asking to try again
# Request ID TextBox
label_ID = tk.Label(root, bg='#17331b', fg='white', text="תעודת זהות")
label_ID.place(x=650, y=300)
ID = tk.Entry(root, width=35)
ID.place(x=550, y=300, width=100)
# Labels
label_PW = tk.Label(root, bg='#17331b', fg='white', text="")
# Login button
sendidbutton = tk.Button(root, text="שחזר סיסמא", command=ForgotPWButton)
sendidbutton.place(x=580, y=350, width=75)
# Function for Menu page for admin user
def MenuPageAdmin():
# StudentDetailsButton
def UpdateDetailsButton():
# clear screen
DetailsButton.destroy()
EraseButton.destroy()
DLGButton.destroy()
ShowStudGameScoreButton.destroy()
# send to update details page
UpadeDetailsPage()
# EraseStudentButton
def EraseStudentButton():
# clear screen
DetailsButton.destroy()
EraseButton.destroy()
DLGButton.destroy()
ShowStudGameScoreButton.destroy()
# send to delete user page
DeleteUser()
# DeleteGameButton
def DeleteLastGameButton():
# clear screen
DetailsButton.destroy()
EraseButton.destroy()
DLGButton.destroy()
ShowStudGameScoreButton.destroy()
# send to delete last game page
DeleteLastGame()
def ShowGameScore():
# clear screen
DetailsButton.destroy()
EraseButton.destroy()
DLGButton.destroy()
ShowStudGameScoreButton.destroy()
# send to show student games page
ShowStudentGames(1)
# Update personal info in info screen
DetailsButton = tk.Button(root, text="עדבן פרטי משתמש", command=UpdateDetailsButton)
DetailsButton.place(x=550, y=450, width=130)
# Erase user
EraseButton = tk.Button(root, text="מחק משתמש", command=EraseStudentButton)
EraseButton.place(x=550, y=400, width=130)
# Erase the last game the user played
DLGButton = tk.Button(root, text="מחק משחק אחרון", command=DeleteLastGameButton)
DLGButton.place(x=550, y=350, width=130)
# Show student games score
ShowStudGameScoreButton = tk.Button(root, text="הצג משחקי תלמיד", command=ShowGameScore)
ShowStudGameScoreButton.place(x=550, y=300, width=130)
# Function for Menu page for Research user
def MenuPageResearch():
# Show Data in a boys\girls cut Button
def BoysGirlsDataButton():
# clear screen
BGDButton.destroy()
SDICButton.destroy()
SDISButton.destroy()
ShowStudGameScoreButton.destroy()
ShowBoysGirls()
# Show Data in a class cut
def ShowDataInClassButton():
# clear screen
BGDButton.destroy()
SDICButton.destroy()
SDISButton.destroy()
ShowStudGameScoreButton.destroy()
# Send to show class data page
ShowClassData()
# Show Data in a schoolName cut
def ShowDataInSchoolButton():
# clear screen
BGDButton.destroy()
SDICButton.destroy()
SDISButton.destroy()
ShowStudGameScoreButton.destroy()
# Show school data page
ShowSchoolData()
# Show student games score
def ShowGameScore():
# clear screen
BGDButton.destroy()
SDICButton.destroy()
SDISButton.destroy()
ShowStudGameScoreButton.destroy()
ShowStudentGames(2)
TitleImage()
# Show Data in a boys\girls cut
BGDButton = tk.Button(root, text="הצג נתונים בחתך בנים ובנות", command=BoysGirlsDataButton)
BGDButton.place(x=520, y=300, width=170)
# Show Data in a class cut
SDICButton = tk.Button(root, text="הצג נתונים בחתך כיתה", command=ShowDataInClassButton)
SDICButton.place(x=520, y=400, width=170)
# Show Data in a schoolName cut
SDISButton = tk.Button(root, text="הצג נתונים בחתך שם בית ספר", command=ShowDataInSchoolButton)
SDISButton.place(x=520, y=350, width=170)
# Show student games score
ShowStudGameScoreButton = tk.Button(root, text="הצג משחקי תלמיד", command=ShowGameScore)
ShowStudGameScoreButton.place(x=520, y=450, width=170)
# Function for Menu page for Student user
def MenuPageStudent(user):
# Game instructions Button
def GameInstructionButton():
D_Message.pack(side="right", fill="both", expand=True)
# Start Game Button
def StartGameButton():
# clear screen
GIButton.destroy()
SGButton.destroy()
SSLGButton.destroy()
Message_Label2.destroy()
StudentFrame.destroy()
InstructionsFrame.destroy()
#send
LevelClass(user)
# Show grade of last game Button
def ShowStudentLastGradeButton():
# clear screen
GIButton.destroy()
SGButton.destroy()
SSLGButton.destroy()
StudentFrame.destroy()
InstructionsFrame.destroy()
#send
ShowLastGames(user)
# Game instructions
GIButton = tk.Button(root, text="הצג את הוראות המשחק", command=GameInstructionButton)
GIButton.place(x=1050, y=180, width=130)
# Start Game
SGButton = tk.Button(root, text="התחל משחק", command=StartGameButton)
SGButton.place(x=550, y=410, width=130, height=50)
# Show grade of last game
SSLGButton = tk.Button(root, text="הצג משחקים אחרונים", command=ShowStudentLastGradeButton)
SSLGButton.place(x=550, y=370, width=130)
# Show Average rank for now
# Get avarage
sql_select = "SELECT points FROM userslist WHERE id = ?"
userlistdata = (user,)
cursor.execute(sql_select, userlistdata)
avgdb = cursor.fetchone()
# Get name
sql_select = "SELECT name FROM userslist WHERE id = ?"
userlistdata = (user,)
cursor.execute(sql_select, userlistdata)
namedb = cursor.fetchone()
# Display
# Frame for message
StudentFrame = tk.Frame(root, bg="#17331b")
StudentFrame.pack()
StudentFrame.place(x=480, y=220, width=320)
avg = "הממוצע שלך הוא "+str(round(avgdb[0],2))
name = "שלום " + namedb[0]
instructions = "באפשרותך לראות את משחקיך האחרונים\nאו להתחיל משחק"
Message_Label2 = tk.Message(StudentFrame, text=name+"\n"+avg + "\n" + instructions,
bg='#17331b',fg="white" , justify="right", width=400 , font=("Ariel", 14), anchor=NE)
Message_Label2.pack(side="right", fill="both", expand=True)
# Frame for detailed instructions
InstructionsFrame = tk.Frame(root, bg="#17331b")
InstructionsFrame.pack()
InstructionsFrame.place(x=820, y=220, width=419)
dinstruct = "תלמידים יקרים" + "\n" + "לפניכם משחק בין שלושה שלבים" + "\n" + "בשלב הראשון תצטרכו למצוא צמדים של מספרים זהים"
dinstruct += "\n"+"בכדי לחשוף את המספרים יש ללחוץ על הקוביות" + "\n" + "במידה והצמד לא זהה המספרים יעלמו בשנית" + "\n"
dinstruct += "\n" + "בשלב השני תופיע רשימה של מספרים שעליכם לזכור לאחר מספר שניות הרשימה תעלם ועליכם להכניס \n את המספרים שזכרתם בתיבות שיופיעו על המסך"
dinstruct += "\n\n" + "בשלב השלישי יופיעו קוביות ממוספרות על המסך\nלאחר כמה רגעים חלק מהקוביות יוארו למספר שניות"
dinstruct += "\n" + "ועליכם להכניס את מספרי הקוביות שהוארו לריבועים המתאימים" + "\n"
dinstruct += "\n" + "שימו לב! לאורך כל המשחק פועל שעון עצר בפינה\n השמאלית העליונה של המסך ובמידה\nונגמר לכם הזמן השלב יסתיים וציונכם יהיה אפס"
D_Message = tk.Message(InstructionsFrame, text=dinstruct,
bg='#17331b',fg="white" , justify="right", width=400 , font=("Ariel", 14), anchor=NE)
# Function that checks if user is Admin\Research\Student user
def CheckUserType(user):
# search for type in db
sql_select_query = "SELECT type FROM userslist WHERE id =?"
userlist = (user,)
cursor.execute(sql_select_query, userlist)
userType = cursor.fetchone()
if userType[0] == 'תלמיד':
MenuPageStudent(user)
if userType[0] == 'חוקר':
MenuPageResearch()
if userType[0] == 'מנהל':
MenuPageAdmin()
# function to show student games details
def ShowStudentGames(type):
# Label for messages
Message_Label = tk.Label(root, bg='#17331b', fg='white', text="")
# var and Label for avg
Message_Label2 = tk.Label(root, bg='#17331b', fg='white', text="")
# Function for return button
def ReturnButton():
# clear screen
Message_Label.destroy()
Message_Label2.destroy()
userID_Label.destroy()
UserID_Entry.destroy()
Show_Button.destroy()
Return_Button.destroy()
tree.destroy()
# send to menu
if type == 1:
MenuPageAdmin()
else:
MenuPageResearch()
# function for show button click
def ShowButton():
# clear data in table
tree.delete(*tree.get_children())
# check if ID is in database
userID = UserID_Entry.get()
sql_select = "SELECT id FROM userslist WHERE id = ?"
userlist = (userID,)
cursor.execute(sql_select, userlist)
IDdb = cursor.fetchone()
if IDdb:
sql_select_data = "SELECT * FROM usergrades WHERE userID = ? ORDER BY attempts"
userlistdata = (userID,)
cursorgrades.execute(sql_select_data, userlistdata)
rows = cursorgrades.fetchall()
for row in rows:
tree.insert("", tk.END, values=row)
tree.place(x=40, y=350)
Message_Label['text'] = "משחקי התלמיד"
Message_Label.place(x=540, y=310, width=120, height=25)
# Get avarage
sql_select = "SELECT points FROM userslist WHERE id = ?"
cursor.execute(sql_select, userlist)
avgdb = cursor.fetchone()
avg = str(avgdb[0])
avg += " ממוצע התלמיד הוא "
Message_Label2['text'] = avg
Message_Label2.place(x=350, y=310, width=170, height=25)
else:
# make tree disappear
tree.place_forget()
# show message
Message_Label['text'] = "משתמש לא נמצא"
Message_Label.place(x=540, y=310, width=120, height=25)
TitleImage()
userID_Label = tk.Label(root, bg='#17331b', fg='white', text="תעודת זהות תלמיד")
userID_Label.place(x=540, y=220, width=120, height=25)
UserID_Entry = tk.Entry(root, width=200)
UserID_Entry.place(x=540, y=250, width=120, height=25)
Show_Button = tk.Button(root, text="הצג", command=ShowButton)
Show_Button.place(x=630, y=280, height=25)
Return_Button = tk.Button(root, text="חזור לתפריט", command=ReturnButton)
Return_Button.place(x=540, y=280, height=25)
# Table to show data
style = ttk.Style(root)
style.theme_use("clam")
style.configure("Treeview",
background="17331b",
foreground="white",
rowheight=25,
fieldbackground="#17331b",
selectbackground="17331b")
tree = ttk.Treeview(root, column=("", "userID", "attempts", "gameTime", "level1", "level2", "level3"),
show='headings')
tree.column("#1", minwidth="0")
tree.column("#1", width=0)
tree.column("#2", anchor=tk.CENTER)
tree.heading("#2", text="תעודת זהות")
tree.column("#3", anchor=tk.CENTER)
tree.heading("#3", text="מספר משחק")
tree.column("#4", anchor=tk.CENTER)
tree.heading("#4", text="תאריך")
tree.column("#5", anchor=tk.CENTER)
tree.heading("#5", text="שלב 1")
tree.column("#6", anchor=tk.CENTER)
tree.heading("#6", text="שלב 2")
tree.column("#7", anchor=tk.CENTER)
tree.heading("#7", text="שלב 3")
tree.pack()
# function to update details of a user
def UpadeDetailsPage():
TitleImage()
# Message Label
Message_Label = tk.Label(root, bg='#17331b', fg='white', text="")
Message_Label2 = tk.Label(root, bg='#17331b', fg='white', text="")
# Function for return Button
def ReturnButton():
# clear screen
Message_Label.destroy()
Message_Label2.destroy()
NameLabel.destroy()
Name.destroy()
CityLabel.destroy()
City.destroy()
SchoolLabel.destroy()
School.destroy()
ClassLabel.destroy()
Class.destroy()
GenderLabel.destroy()
Gender.destroy()
PasswordLabel.destroy()
PasswordFirst.destroy()
TypeLabel.destroy()
Type.destroy()
QuestionLabel.destroy()
Question.destroy()
AnswerLabel.destroy()
Answer.destroy()
UpdateButton.destroy()
userID_Label.destroy()
UserID_Entry.destroy()
Show_Button.destroy()
Return_Button.destroy()
# Send to menu
MenuPageAdmin()
# Function for show button:
def ShowButton():
# check if ID is in database
userID = UserID_Entry.get()
sql_select = "SELECT * FROM userslist WHERE id = ?"
userlist = (userID,)
cursor.execute(sql_select, userlist)
IDdb = cursor.fetchone()
if IDdb:
Message_Label['text'] = "פרטי המשתמש"
NameLabel.place(x=920, y=300, width=75)
Name.place(x=800, y=300, width=100)
CityLabel.place(x=920, y=400, width=75)
City.place(x=800, y=400, width=100)
SchoolLabel.place(x=920, y=450, width=75)
School.place(x=800, y=450, width=100)
ClassLabel.place(x=920, y=500, width=75)
Class.place(x=800, y=500, width=90)
GenderLabel.place(x=920, y=550, width=75)
Gender.place(x=800, y=550, width=70)
PasswordLabel.place(x=520, y=380, width=175, height=35)
PasswordFirst.place(x=520, y=420, width=174, height=25)
TypeLabel.place(x=920, y=350, height=35)
Type.place(x=800, y=350, width=70)
Question.place(x=250, y=420, width=174, height=25)
QuestionLabel.place(x=250, y=380, width=175, height=35)
Answer.place(x=250, y=510, width=174)
AnswerLabel.place(x=250, y=470, width=175, height=35)
UpdateButton.place(x=580, y=610, width=80, height=25)
Name.delete(0, END)
Name.insert(0, IDdb[0])
City.delete(0, END)
City.insert(0, IDdb[2])
School.delete(0, END)
School.insert(0, IDdb[3])
GenderVar.set(IDdb[4])
ClassVar.set(IDdb[5])
TypeVar.set(IDdb[6])
PasswordFirst.delete(0, END)
PasswordFirst.insert(0, IDdb[7])
Question.delete(0, END)
Question.insert(0, IDdb[9])
Answer.delete(0, END)
Answer.insert(0, IDdb[10])
else:
Message_Label['text'] = "משתמש לא נמצא"
Message_Label.place(x=540, y=310, width=120, height=25)
Message_Label2.place_forget()
Name.delete(0, END)
City.delete(0, END)
School.delete(0, END)
GenderVar.set("")
ClassVar.set("")
TypeVar.set("")
PasswordFirst.delete(0, END)
Question.delete(0, END)
Answer.delete(0, END)
UpdateButton.place_forget()
NameLabel.place_forget()
Name.place_forget()
CityLabel.place_forget()
City.place_forget()
SchoolLabel.place_forget()
School.place_forget()
ClassLabel.place_forget()
Class.place_forget()
GenderLabel.place_forget()
Gender.place_forget()
PasswordLabel.place_forget()
PasswordFirst.place_forget()
TypeLabel.place_forget()
Type.place_forget()
Question.place_forget()
QuestionLabel.place_forget()
Answer.place_forget()
AnswerLabel.place_forget()
# Function for update button
def UpdateButton():
userID = UserID_Entry.get()
name_user = Name.get()
city_user = City.get()
school_user = School.get()
class_user = ClassVar.get()
gender_user = GenderVar.get()
type_user = TypeVar.get()
question_user = Question.get()
answer_user = Answer.get()
user_password = PasswordFirst.get()
sql_update = "UPDATE userslist SET name= ? , city= ? , school= ? , gender = ? , class = ? , type = ?" \
" , password = ? , question = ? , answer = ? WHERE id = ?"
val = (name_user, city_user, school_user, gender_user, class_user, type_user, user_password,
question_user, answer_user, userID)
cursor.execute(sql_update, val)
sqlconnect.commit()
Message_Label2.configure(text="העדכון בוצע בהצלחה , אנא חזור לתפריט")
Message_Label2.place(x=520, y=640, width=250, height=25)
# Detail fields:
# Name
NameLabel = Label(root, bg='#17331b', fg='white', text="שם מלא", )
Name = tk.Entry(root, width=35)
# City
CityLabel = Label(root, bg='#17331b', fg='white', text="עיר מגורים", )
City = tk.Entry(root, width=35)
# School
SchoolLabel = Label(root, bg='#17331b', fg='white', text="שם בית הספר", )
School = tk.Entry(root, width=35)
# Class
ClassLabel = Label(root, bg='#17331b', fg='white', text="כיתה", )
ClassVar = StringVar(root)
Class = tk.OptionMenu(root, ClassVar, "א", "ב", "ג", "ד", "ה", "ו", "לא רלוונטי")
Class.pack
# Gender
GenderLabel = Label(root, bg='#17331b', fg='white', text="מין", )
GenderVar = StringVar(root)
Gender = tk.OptionMenu(root, GenderVar, "זכר", "נקבה")
Gender.pack()
# Password
PasswordLabel = Label(root, bg='#17331b', fg='white', text="סיסמא אישית (לפחות 6 תווים)", )
PasswordFirst = tk.Entry(root, width=35)
# Type
TypeLabel = Label(root, bg='#17331b', fg='white', text="סוג משתמש", )
TypeVar = StringVar(root)
Type = tk.OptionMenu(root, TypeVar, "תלמיד", "מנהל", "חוקר")
Type.pack()
# Question
QuestionLabel = Label(root, bg='#17331b', fg='white', text="שאלת אבטחה", )
Question = tk.Entry(root, width=35)
# Answer Title
AnswerLabel = Label(root, bg='#17331b', fg='white', text="תשובת אבטחה", )
Answer = tk.Entry(root, width=35)
# Update Button
UpdateButton = tk.Button(root, text="עדכן", command=UpdateButton)
userID_Label = tk.Label(root, bg='#17331b', fg='white', text="תעודת זהות משתמש")
userID_Label.place(x=540, y=220, width=120, height=25)
UserID_Entry = tk.Entry(root, width=200)
UserID_Entry.place(x=540, y=250, width=120, height=25)
Show_Button = tk.Button(root, text="הצג", command=ShowButton)
Show_Button.place(x=630, y=280, height=25)
Return_Button = tk.Button(root, text="חזור לתפריט", command=ReturnButton)
Return_Button.place(x=540, y=280, height=25)
# Function for delete user page
def DeleteUser():
TitleImage()
# Label Message
Label_Message = tk.Label(root, bg='#17331b', fg='white', text="")
# Function for return button
def ReturnButton():
# clear screen
Label_Message.destroy()
userID_Label.destroy()
UserID_Entry.destroy()
Show_Button.destroy()
Return_Button.destroy()
# back to menu
MenuPageAdmin()
# Function for delete button
def DeleteButton():
# check if ID is in database
userID = UserID_Entry.get()
sql_select = "SELECT * FROM userslist WHERE id = ?"
userlist = (userID,)
cursor.execute(sql_select, userlist)
IDdb = cursor.fetchone()
if IDdb:
sql_delete = "DELETE FROM userslist WHERE id = ?"
cursor.execute(sql_delete, userlist)