-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDashboard.py
1614 lines (1459 loc) · 65.5 KB
/
Dashboard.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
import tkinter.font as tkFont
import tkinter as tk
from tkinter import ttk
from tkinter import *
from ctypes import windll
from tkinter import filedialog
import os
import sys
from types import CellType
import pymysql
import xlrd
import csv
import pandas as pd
from tkinter import messagebox
import mysql.connector
import webbrowser
from PIL import Image, ImageTk
import matplotlib.pyplot as plt
import base64
target = int
clicked = 0
input_clicked = 0
output_clicked = 0
visualize = 0
update_clicked = 0
def login_screen():
# get login name
def login_name():
return login.get()
# register window
def register_action(event):
# return button pressed
def out_action(event):
register_main.destroy()
login_screen()
# signup button pressed
def done_action(event):
# database saved
email_required = "@gmail.com"
if (
confirm_password_set.get() != password_reg_set.get()
and len(confirm_password_set.get()) != 0
and len(password_reg_set.get()) != 0
):
warning_window = tk.Tk()
warning_window.geometry("360x60+900+300")
warning_window.title("Warning")
warning_window.resizable(False, False)
unmatched = ttk.Label(
warning_window,
text="Passwords do not match",
foreground="red",
font=("Segoe UI", 10, "italic"),
)
unmatched.place(x=110, y=20)
warning_window.mainloop()
elif changed.get() == 0:
warning_window = tk.Tk()
warning_window.geometry("360x60+900+300")
warning_window.title("Warning")
warning_window.resizable(False, False)
term_warning = ttk.Label(
warning_window,
text="You need to agree with our Terms and Conditions ",
foreground="red",
font=("Segoe UI", 10, "italic"),
)
term_warning.place(x=48, y=20)
warning_window.mainloop()
elif (
len(confirm_password_set.get()) == 0
or len(password_reg_set.get()) == 0
or len(email_set.get()) == 0
or len(username_set.get()) == 0
):
warning_window = tk.Tk()
warning_window.geometry("360x60+900+300")
warning_window.title("Warning")
warning_window.resizable(False, False)
missing_warning = ttk.Label(
warning_window,
text="Field(s) required",
foreground="red",
font=("Segoe UI", 12, "italic"),
)
missing_warning.place(x=128, y=20)
warning_window.mainloop()
elif email_required not in email_set.get():
warning_window = tk.Tk()
warning_window.geometry("360x60+900+300")
warning_window.title("Warning")
warning_window.resizable(False, False)
mail_format = ttk.Label(
warning_window,
text="Email format is incorrect or not supported",
font=("Segoe UI", 10, "italic"),
foreground="red",
)
mail_format.place(x=65, y=20)
warning_window.mainloop()
else:
database = mysql.connector.connect(
host="DESKTOP-1NPT2KL",
user="Dashboard",
password="Haido29904",
database="login_info",
)
cursor = database.cursor(buffered=True)
cursor.execute(
"CREATE TABLE IF NOT EXISTS login(id INT PRIMARY KEY AUTO_INCREMENT, email VARCHAR(255), username VARCHAR(255), password_text VARCHAR(255))")
reg = (
"INSERT INTO login (email,username,password_text) VALUES (%s,%s,%s)"
)
login_val = (
email_set.get(),
username_set.get(),
password_reg_set.get(),
)
cursor.execute(reg, login_val)
database.commit()
register_main.destroy()
login_screen()
# register window
root.destroy()
register_main = tk.Tk()
register_main.title("Register")
register_main.resizable(width=False, height=False)
register_main.geometry("320x240+850+250")
email = ttk.Label(register_main, text="Email: ",
font=("Segoe UI", 10, "bold"))
email.pack()
email.place(x=10, y=7)
email_set = ttk.Entry(register_main)
email_set.pack(pady=10, ipadx=10)
username = ttk.Label(
register_main, text="Username:", font=("Segoe UI", 10, "bold")
)
username.pack()
username.place(x=10, y=50)
username_set = ttk.Entry(register_main)
username_set.pack(pady=10, ipadx=10)
password_reg = ttk.Label(
register_main, text="Password:", font=("Segoe UI", 10, "bold")
)
password_reg.pack()
password_reg.place(x=10, y=90)
password_reg_set = ttk.Entry(register_main)
password_reg_set.pack(pady=10, ipadx=10)
confirm_password = ttk.Label(
register_main, text="Confirm \nPassword:", font=("Segoe UI", 10, "bold")
)
confirm_password.pack()
confirm_password.place(x=10, y=115)
confirm_password_set = ttk.Entry(register_main)
confirm_password_set.pack(pady=10, ipadx=10)
changed = IntVar(register_main)
changed.set(0)
check = tk.Checkbutton(
register_main,
variable=changed,
onvalue=1,
offvalue=0,
text="I agree with the terms and conditions of services.",
fg="blue",
)
check.pack()
done = ttk.Button(register_main, text="Sign up", cursor="hand2")
done.bind("<Button>", done_action)
done.place(x=180, y=190, height=40, width=100)
out = ttk.Button(register_main, text="Return", cursor="hand2")
out.bind("<Button>", out_action)
out.place(x=40, y=190, height=40, width=100)
register_main.mainloop()
# login function
def login_action(event):
global target
database = mysql.connector.connect(
host="DESKTOP-1NPT2KL",
user="Dashboard",
password="Haido29904",
database="login_info",
)
cursor = database.cursor()
command = str(
"SELECT password_text FROM login_info.login WHERE username = '{}'"
).format(login.get())
cursor.execute(command)
result_pass = cursor.fetchone()
if not login.get() or not password.get():
not_found = tk.Tk()
not_found.geometry("360x60+900+300")
not_found.title("Login Checker")
not_found.resizable(False, False)
status = tk.Label(
not_found,
text="Username/Password is missing!",
font=("Segoe UI", 12),
foreground="red",
)
status.place(x=70, y=13)
not_found.mainloop()
elif not result_pass:
not_found = tk.Tk()
not_found.geometry("360x60+900+300")
not_found.title("Login Checker")
not_found.resizable(False, False)
status = tk.Label(
not_found,
text="Username/Password is incorrect!",
font=("Segoe UI", 12),
foreground="red",
)
status.place(x=70, y=13)
not_found.mainloop()
elif result_pass[0] == password.get():
command = str(
"SELECT id FROM login_info.login WHERE username = '{}' AND password_text = '{}'"
).format(login.get(), password.get())
cursor.execute(command)
result_id = cursor.fetchone()
target = result_id[0]
# create user database:
cursor_2 = database.cursor(buffered=True)
cursor_2.execute(
"CREATE TABLE IF NOT EXISTS USER_NO_{}(id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), price INT, quantity INT, tag VARCHAR(255), total_value INT)".format(
str(target)
)
)
cursor_2.execute("SET SQL_SAFE_UPDATES = 0")
root.destroy()
cursor.close()
database.close()
dashboard()
else:
fail = tk.Tk()
fail.geometry("360x60+900+300")
fail.title("Login Checker")
fail.resizable(False, False)
status = tk.Label(
fail,
text="Username/Password is incorrect!",
font=("Segoe UI", 12),
foreground="red",
)
status.place(x=70, y=13)
fail.mainloop()
# main window
root = tk.Tk()
root.geometry("320x240+850+250")
root.resizable(False, False)
root.title("Login")
login_text = ttk.Label(text="Username", font=("Segoe UI", 12, "bold"))
login_text.pack()
login = ttk.Entry()
login.pack(ipadx=10, ipady=3)
login.bind("<Return>", login_action)
password_text = ttk.Label(text="Password", font=("Segoe UI", 12, "bold"))
password_text.pack()
password = ttk.Entry(show="*")
password.pack(ipadx=10, ipady=3)
password.bind("<Return>", login_action)
start_login = ttk.Button(text="Login", cursor="hand2")
start_login.pack(anchor="center", pady=20, ipadx=5)
start_login.bind("<Button>", login_action)
register = ttk.Label(
text="Register", font=("Segoe UI", 12, "italic", "underline"), cursor="hand2"
)
register.bind("<Button>", register_action)
register.pack(anchor="center")
root.mainloop()
# Dashboard
def dashboard():
global target
def menu_entry(event):
global clicked
if clicked % 2 == 0:
menu.pack(ipadx=30)
menu_icon.place(x=13)
input_data.place_forget()
update_data.place_forget()
output_data.place_forget()
graph_data.place_forget()
log_out.place_forget()
input_icon_label.place(x=5, y=110)
center_icon_label.place(x=5, y=375)
bar_icon_label.place(x=5, y=520)
exit_icon_label.place(x=5, y=650)
update_icon_label.place(x=5, y=240)
clicked += 1
else:
input_icon_label.place_forget()
center_icon_label.place_forget()
bar_icon_label.place_forget()
exit_icon_label.place_forget()
update_icon_label.place_forget()
menu_icon.place(x=260, y=73)
menu.pack(side=LEFT, ipadx=150, ipady=350)
input_data.place(x=0, y=110, height=60, width=304)
update_data.place(x=0, y=240, height=60, width=304)
output_data.place(x=0, y=380, height=60, width=304)
graph_data.place(x=0, y=520, width=304, height=60)
log_out.place(x=0, y=650, width=304, height=60)
clicked += 1
# Input function:
def input_functions(event):
global input_clicked
global output_clicked
global visualize
# return button
def return_action(event):
global input_clicked
input_clicked = 0
frame.destroy()
welcome_frame.pack()
# main frame create:
if input_clicked == 0 and output_clicked == 0 and visualize == 0:
# Database for items
welcome_frame.pack_forget()
database = mysql.connector.connect(
host="DESKTOP-1NPT2KL",
user="Dashboard",
password="Haido29904",
database="login_info",
)
cursor_2 = database.cursor(buffered=True)
def get_input(event):
cursor_2.execute(
"SELECT name FROM user_no_{} WHERE name = '{}'".format(
str(target), get_name.get()
)
)
check_exist = cursor_2.fetchone()
if (
len(get_name.get()) == 0
or len(get_price.get()) == 0
or len(get_quantity.get()) == 0
or len(get_priority.get()) == 0
):
messagebox.showwarning("Alert!", "Field(s) required")
elif not check_exist:
items = "INSERT INTO USER_NO_{}(name, price, quantity, tag) VALUES( %s, %s, %s, %s)".format(
str(target)
)
items_info = (
get_name.get(),
get_price.get(),
get_quantity.get(),
get_priority.get(),
)
cursor_2.execute(items, items_info)
cursor_2.execute(
"UPDATE USER_NO_{} SET total_value = price * quantity".format(
str(target)
)
)
database.commit()
messagebox.showinfo("Done!", "Updated Successfully")
elif check_exist[0] == get_name.get():
messagebox.showwarning("Alert!", "Items exists!")
frame = tk.Frame(root, background="#B1B2FF")
# left bar:
left = tk.Label(frame, background="#F29393")
left.pack(side=LEFT, ipadx=10, ipady=1000)
# right bar:
right = ttk.Label(frame, background="#F29393")
right.pack(side=RIGHT, ipadx=10, ipady=1000)
# top bar:
top = tk.Label(frame, background="#F29393")
top.pack(side=TOP, ipadx=1000, ipady=5)
# bottom bar:
bottom = tk.Label(frame, background="#F29393")
bottom.pack(side=BOTTOM, ipadx=1000, ipady=5)
# Item name:
name = ttk.Label(
frame,
text="Item's Name: ",
font=("Broken Console", 16, "bold"),
foreground="#4169e1",
background="#B1B2FF",
)
name.place(relx=0.05, rely=0.12)
get_name = ttk.Entry(frame, font=("Montserrat", 25))
get_name.place(relx=0.3, rely=0.1, relwidth=0.6)
# Item price:
price = ttk.Label(
frame,
text="Item's Price: ",
font=("Broken Console", 16, "bold"),
foreground="#4169e1",
background="#B1B2FF",
)
price.place(relx=0.05, rely=0.32)
get_price = ttk.Entry(frame, font=("Montserrat", 25))
get_price.place(relx=0.3, rely=0.3, relwidth=0.6)
# Item quantity:
quantity = ttk.Label(
frame,
text="Item's Quantity: ",
font=("Broken Console", 16, "bold"),
foreground="#4169e1",
background="#B1B2FF",
)
quantity.place(relx=0.05, rely=0.52)
get_quantity = ttk.Spinbox(
frame, font=("Montserrat", 25), from_=1, to=1000000, wrap=True
)
get_quantity.place(relx=0.3, rely=0.5, relwidth=0.6)
# Item priority
priority = ttk.Label(
frame,
text="Item's Priority: ",
font=("Broken Console", 16, "bold"),
foreground="#4169e1",
background="#B1B2FF",
)
priority.place(relx=0.05, rely=0.72)
get_priority = ttk.Combobox(frame, font=("Montserrat", 25))
font = tkFont.Font(family="Montserrat", size=18)
frame.option_add("*TCombobox*Listbox*Font", font)
get_priority["value"] = (
"High",
"Medium",
"Low",
"Emergency",
"Redundancy",
"Spontaneous",
"None",
)
get_priority["state"] = "readonly"
get_priority.place(relx=0.3, rely=0.7, relwidth=0.6)
# Database log:
log = ttk.Button(frame, text="Enter")
log.place(relx=0.75, rely=0.8, relwidth=0.15, relheight=0.05)
log.bind("<Button>", get_input)
# Return button:
return_button = ttk.Button(frame, text="Return")
return_button.place(relx=0.25, rely=0.8,
relwidth=0.15, relheight=0.05)
return_button.bind("<Button>", return_action)
# frame show:
frame.pack(fill=BOTH, expand=True)
input_clicked += 1
# file output functions:
def output_functions(event):
global output_clicked
global input_clicked
global visualize
# return button pressed
def return_action(event):
global output_clicked
output_clicked = 0
frame.destroy()
welcome_frame.pack()
# get output function if:
if output_clicked == 0 and input_clicked == 0 and visualize == 0:
# select directory:
def dir_select(event):
dir = filedialog.askdirectory()
if len(dir) != 0:
os.chdir(dir)
if len(dir_text.get()) == 0:
dir_text.insert(0, dir)
elif len(dir_text.get()) != 0 and len(dir) != 0:
dir_text.delete(0, END)
dir_text.insert(0, dir)
# file selection
def file_action(event):
file_select = filedialog.askopenfilename(
filetypes=(("Excel(.xls)", "*.xls"),
("CSV(.csv)", "*.csv*"))
)
if len(file_select) != 0 and len(file_entry.get()) != 0:
file_entry.delete(0, END)
file_entry.insert(0, file_select)
elif len(file_entry.get()) == 0:
file_entry.insert(0, file_select)
# save to csv:
def csv_save(event):
path = (dir_text.get()) + (
"/USER_NO_{}".format(str(target)) + " Log File" + ".csv"
)
database_get = mysql.connector.connect(
host="DESKTOP-1NPT2KL",
user="Dashboard",
password="Haido29904",
database="login_info",
)
cursor_3 = database_get.cursor()
try:
cursor_3.execute(
"SELECT * FROM login_info.USER_NO_{}".format(
str(target))
)
result = cursor_3.fetchall()
finally:
database_get.close()
# get column name ie: name, price,...
column_names = list()
# append all column names to result list
for i in cursor_3.description:
column_names.append(i[0])
result.append(column_names)
# write to csv file:
with open(path, "w", newline="") as csv_file:
csvsave = csv.writer(
csv_file, delimiter=",", quoting=csv.QUOTE_NONE
)
for row in result:
csvsave.writerow(row)
# open notification window
messagebox.showinfo("Saved", "File saved successfully!")
# save to excel:
def xls_save(event):
path = (
(dir_text.get())
+ "/USER_NO_{}".format(str(target))
+ " Log File"
+ ".xls"
)
database_get = mysql.connector.connect(
host="DESKTOP-1NPT2KL",
user="Dashboard",
password="Haido29904",
database="login_info",
)
data_frame = pd.read_sql(
"SELECT * FROM login_info.USER_NO_{}".format(
target), database_get
)
data_frame.to_excel(path, index=False)
messagebox.showinfo("Saved", "File saved successfully!")
# load to database
def load_file(event):
global target
path = file_entry.get()
if not path:
warning = messagebox.showwarning("File not found!")
warning.pack()
else:
database = mysql.connector.connect(
host="DESKTOP-1NPT2KL",
user="Dashboard",
password="Haido29904",
database="login_info",
)
cursor_load = database.cursor()
cursor_load.execute(
"DROP TABLE IF EXISTS USER_NO_{}".format(str(target))
)
cursor_load.execute(
"CREATE TABLE IF NOT EXISTS USER_NO_{}(id INTEGER PRIMARY KEY, name VARCHAR(255), price INTEGER, quantity INTEGER, tag VARCHAR(255))".format(
str(target)
)
)
insert = "INSERT into USER_NO_{}(id, name, price, quantity, tag) VALUES (%s, %s, %s, %s, %s)".format(
str(target)
)
if path.endswith(".csv"):
file = open(path)
csv_data = csv.reader(file)
for row in csv_data:
cursor_load.execute(insert, tuple(row))
database.commit()
cursor_load.close()
file.close()
database.close()
elif path.endswith(".xls"):
file_load = xlrd.open_workbook_xls(path)
excel_name = file_load.sheet_names()
sheet = file_load.sheet_by_name(excel_name[0])
for row in range(1, sheet.nrows):
id = sheet.cell(row, 0).value
name = sheet.cell(row, 1).value
price = sheet.cell(row, 2).value
quantity = sheet.cell(row, 3).value
tag = sheet.cell(row, 4).value
values = (id, name, price, quantity, tag)
cursor_load.execute(insert, tuple(values))
database.commit()
database.close()
cursor_load.close()
messagebox.showinfo(
"Congratulate!", "File loaded successfully!")
# main output frame
welcome_frame.pack_forget()
frame = tk.Frame(root, background="#B1B2FF")
# left bar:
left = tk.Label(frame, background="#F29393")
left.pack(side=LEFT, ipadx=10, ipady=1000)
# right bar:
right = tk.Label(frame, background="#F29393")
right.pack(side=RIGHT, ipadx=10, ipady=1000)
# top bar:
top = tk.Label(frame, background="#F29393")
top.pack(side=TOP, ipadx=1000, ipady=5)
# bottom bar:
bottom = tk.Label(frame, background="#F29393")
bottom.pack(side=BOTTOM, ipadx=1000, ipady=5)
# Title:
title = ttk.Label(
frame,
text="Welcome to the file center",
foreground="#ff6961",
font=("Broken Console", 25, "bold"),
background="#B1B2FF",
)
title.config(anchor=CENTER)
title.place(relx=0.027, rely=0.1, relwidth=0.945, relheight=0.1)
# Directory:
dir = ttk.Button(frame, text="Choose \n directory")
dir.place(relx=0.66, rely=0.24, relwidth=0.07, relheight=0.07)
dir.bind("<Button>", dir_select)
dir_text = ttk.Entry(frame)
dir_text.place(relx=0.29, rely=0.25, relwidth=0.35, relheight=0.05)
# Save to csv function;
csv_button = ttk.Button(frame, text="Save to csv")
csv_button.place(relx=0.3, rely=0.45, relwidth=0.1, relheight=0.1)
csv_button.bind("<Button>", csv_save)
# save to excel
excel_button = ttk.Button(frame, text="Save to excel")
excel_button.place(relx=0.6, rely=0.45,
relwidth=0.1, relheight=0.1)
excel_button.bind("<Button>", xls_save)
# select file entry and button
file_select = ttk.Button(frame, text="Choose file \n (csv or xls)")
file_select.place(relx=0.66, rely=0.65,
relwidth=0.075, relheight=0.07)
file_select.bind("<Button>", file_action)
file_entry = ttk.Entry(frame)
file_entry.place(relx=0.29, rely=0.66,
relwidth=0.35, relheight=0.05)
# load file
load_func = ttk.Button(frame, text="Load file")
load_func.place(relx=0.45, rely=0.75, relwidth=0.1, relheight=0.05)
load_func.bind("<Button>", load_file)
# return button functions:
return_button = ttk.Button(frame, text="Return")
return_button.place(relx=0.45, rely=0.85,
relwidth=0.1, relheight=0.05)
return_button.bind("<Button>", return_action)
# show frame:
frame.pack(fill=BOTH, expand=True)
output_clicked += 1
# data visualization
def get_visualization_frame(event):
global input_clicked
global output_clicked
global visualize
global target
# return button function:
def return_func(event):
global visualize
visualize = 0
frame.destroy()
welcome_frame.pack()
# data visualization frame
if input_clicked == 0 and output_clicked == 0 and visualize == 0:
welcome_frame.pack_forget()
frame = tk.Frame(root, background="#B1B2FF")
# left bar:
left = tk.Label(frame, background="#F29393")
left.pack(side=LEFT, ipadx=10, ipady=1000)
# right bar:
right = ttk.Label(frame, background="#F29393")
right.pack(side=RIGHT, ipadx=10, ipady=1000)
# top bar:
top = tk.Label(frame, background="#F29393")
top.pack(side=TOP, ipadx=1000, ipady=5)
# bottom bar:
bottom = tk.Label(frame, background="#F29393")
bottom.pack(side=BOTTOM, ipadx=1000, ipady=5)
def graph_draw(event):
global target
database = mysql.connector.connect(
host="DESKTOP-1NPT2KL",
user="Dashboard",
password="Haido29904",
database="login_info",
)
cursor = database.cursor()
if graph_info.get() == "Retail Price":
cursor.execute(
"SELECT name, price FROM USER_NO_{}".format(
str(target))
)
result = cursor.fetchall()
name = []
price = []
for i in result:
name.append(i[0])
price.append(int(i[1]))
plt.figure(figsize=(12, 6.75))
# label adding:
def add_labels():
for i in range(len(name)):
plt.text(i, price[i], price[i], ha="center")
# matplotlib plotting:
if graph_type.get() == "Bar":
# bar graph:
plt.bar(
name,
price,
color=("#5B8899", "#FF1205", "#52D452"),
width=0.3,
)
plt.xlabel("Name of item")
plt.ylabel("Retail price of items")
plt.title("Retail price per item")
add_labels()
plt.show()
# line graph
elif graph_type.get() == "Line":
# line graph:
plt.plot(name, price, color=("#FF3D33"))
plt.xlabel("Name of items")
plt.ylabel("Price of items")
plt.title("Retail price per item")
add_labels()
plt.show()
elif graph_type.get() == "Pie":
wedge = {"linewidth": 1, "edgecolor": "black"}
plt.pie(
price,
radius=1,
startangle=90,
wedgeprops=wedge,
autopct="%1.1f%%",
)
plt.title("Retail price per item")
plt.legend(
title="Name of items",
loc="upper right",
labels=name,
bbox_to_anchor=(1.15, 0.65),
)
plt.show()
elif graph_info.get() == "Quantity":
cursor.execute(
"SELECT name, quantity FROM USER_NO_{}".format(
str(target))
)
result = cursor.fetchall()
name = []
quantity = []
plt.figure(figsize=(12, 6.75))
for i in result:
name.append(i[0])
quantity.append(i[1])
def add_label():
for i in range(len(name)):
plt.text(i, quantity[i], quantity[i], ha="center")
if graph_type.get() == "Bar":
# Bar graph
plt.bar(
name,
quantity,
color=("#5B8899", "#FF1205", "#52D452"),
width=0.3,
)
plt.title("Quantity per category")
plt.xlabel("Name of items")
plt.ylabel("Quantity of items")
add_label()
plt.show()
elif graph_type.get() == "Line":
# Line graph:
plt.plot(name, quantity, color="#FF3D33")
plt.title("Quantity per category")
plt.xlabel("Name of items")
plt.ylabel("Quantity of items")
add_label()
plt.show()
elif graph_type.get() == "Pie":
# Pie graph:
wedge = {"linewidth": 1, "edgecolor": "black"}
def make_autopct(quantity):
def autopct_maker(pct):
total = sum(quantity)
val = int(round(pct * total / 100.0))
return "{p:.1f}% ({v:d})".format(p=pct, v=val)
return autopct_maker
plt.pie(
quantity,
radius=1,
startangle=90,
wedgeprops=wedge,
autopct=make_autopct(quantity),
)
plt.title("Quantity per category")
plt.legend(
title="Name of items",
loc="upper right",
labels=name,
bbox_to_anchor=(1.15, 0.65),
)
plt.show()
elif graph_info.get() == "Total Value":
# Total value graph:
plt.figure(figsize=(12, 6.75))
cursor.execute(
"SELECT name, total_value FROM USER_NO_{}".format(
str(target))
)
result = cursor.fetchall()
name = []
total_value = []
for i in result:
name.append(i[0])
total_value.append(i[1])
def add_value():
for i in range(len(name)):
plt.text(i, total_value[i],
total_value[i], ha="center")
# Bar graph:
if graph_type.get() == "Bar":
plt.bar(
name,
total_value,
width=0.3,
color=("#5B8899", "#FF1205", "#52D452"),
)
plt.title("Total value per item")
plt.xlabel("Name of items")
plt.ylabel("Total value per item")
add_value()
plt.show()
# line graph:
elif graph_type.get() == "Line":
plt.plot(name, total_value, color="#FF3D33")
plt.title("Total value per item")
plt.xlabel("Name of items")
plt.ylabel("Total value of per item")
add_value()
plt.show()
# pie graph:
elif graph_type.get() == "Pie":
wedge = {"linewidth": 1, "edgecolor": "black"}
def make_autopct(total_value):
def autopct_maker(pct):
total = sum(total_value)
val = int(round(pct * total / 100.0))
return "{p:.1f}% ({v:d})".format(p=pct, v=val)
return autopct_maker
plt.pie(
total_value,
radius=1,
startangle=90,
wedgeprops=wedge,
autopct=make_autopct(total_value),
)
plt.legend(name, loc="upper right",
bbox_to_anchor=(1.15, 0.65))
plt.title("Total value per item")
plt.show()
elif graph_info.get() == "Priority":
cursor = database.cursor()
cursor.execute(
"SELECT tag FROM USER_NO_{}".format(str(target)))
result = cursor.fetchall()
tag = []
for row in result:
tag.append(row[0])
count_tag = [0, 0, 0, 0, 0, 0, 0]
for i in tag:
if i == 'High':
count_tag[0] += 1
elif i == 'Medium':
count_tag[1] += 1
elif i == 'Low':
count_tag[2] += 1
elif i == 'Emergency':
count_tag[3] += 1
elif i == 'Redundancy':
count_tag[4] += 1
elif i == 'Spontaneous':
count_tag[5] += 1
elif i == 'None':
count_tag[6] += 1
name_tag = ['High', 'Medium', 'Low', 'Emergency',
'Redundancy', 'Spontaneous', 'None']
def add_values():
for i in range(len(count_tag)):
plt.text(i, count_tag[i],
count_tag[i], ha='center')
if graph_type.get() == "Bar":
plt.bar(name_tag, count_tag, color=("#5B8899", "#FF1205", "#52D452"),
width=0.3)
plt.title("Priority Distribution")
plt.xlabel('Priority type')
plt.ylabel('Number of items')
add_values()
plt.show()
elif graph_type.get() == "Line":
plt.plot(name_tag, count_tag)
plt.title("Priority Distribution")
plt.xlabel('Priority type')
plt.ylabel('Number of items')
add_values()
plt.show()
elif graph_type.get() == "Pie":
def make_autopct(count_tag):
def autopct_maker(pct):
total = sum(count_tag)
val = int(round(pct * total / 100.0))
return "({p:.1f}% {v:d})".format(p=pct, v=val)
return autopct_maker
wedges = {"linewidth": 1, "edgecolor": "black"}
plt.pie(count_tag, radius=1, startangle=90,
wedgeprops=wedges, autopct=make_autopct(count_tag))
plt.title("Priority Distribution")
plt.legend(labels=name_tag, loc='upper right',
bbox_to_anchor=(1.15, 0.65))
plt.show()
# Graphing:
graph_text = ttk.Label(
frame,
text="Choose a attribute to display",
foreground="#4169e1",
background="#B1B2FF",
font=("Broken Console", 18),
)
graph_text.config(anchor=CENTER)