-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_interface.py
More file actions
110 lines (76 loc) · 3.08 KB
/
user_interface.py
File metadata and controls
110 lines (76 loc) · 3.08 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
import customtkinter as ctk
from tkinter import filedialog
import logic
def browse_file():
file_path = filedialog.askopenfilename(
title="Select a file",
filetypes=[("All Files", "*.*")]
)
if file_path:
path_input.delete(0, ctk.END)
path_input.insert(0, file_path)
def submit_encrypt():
path = path_input.get()
password = password_input.get()
if path == "" or password == "":
success_label.configure(text='file path or password not provided',text_color="#ca0f0f")
else:
path_input.delete(0, ctk.END)
password_input.delete(0, ctk.END)
result = logic.encrypt_file(path, password)
if result == True:
success_label.configure(text='Encrypted file successfully saved at the path',text_color="#32CD32")
else:
success_label.configure(text='Unexpected error',text_color="#ca0f0f")
def submit_decrypt():
path = path_input.get()
password = password_input.get()
if path == "" or password == "":
success_label.configure(text='file path or password not provided',text_color="#ca0f0f")
else:
path_input.delete(0, ctk.END)
password_input.delete(0, ctk.END)
result = logic.decrypt_file(path, password)
if result == True:
success_label.configure(text='File successfully decrypted and saved at the path',text_color="#32CD32")
else:
success_label.configure(text='Unexpected error',text_color="#ca0f0f")
def switch_mode():
if mode.get() == "Encryption":
mode.set("Decryption")
label_mode.configure(text="Mode: Decryption")
submit_button.configure(text="Decrypt",command=submit_decrypt)
else:
mode.set("Encryption")
label_mode.configure(text="Mode: Encryption")
submit_button.configure(text="Encrypt",command=submit_encrypt)
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("green")
app = ctk.CTk()
app.title("Encryptify")
app.geometry("1280x720")
mode = ctk.StringVar(value="Encryption")
#Mode
label_mode = ctk.CTkLabel(app, text=f"Mode: {mode.get()}", font=("Arial", 20))
label_mode.pack(pady=40)
# file path
label_path = ctk.CTkLabel(app, text="File Path", font=("Arial", 12))
label_path.pack(pady=1)
path_frame = ctk.CTkFrame(app)
path_frame.pack()
path_input = ctk.CTkEntry(path_frame, width=350, placeholder_text="Select file...")
path_input.pack(side="left", padx=5)
browse_button = ctk.CTkButton(path_frame, text="Browse", width=80, command=browse_file)
browse_button.pack(side="left", padx=5)
#password
label_pass = ctk.CTkLabel(app, text="password", font=("Arial", 12))
label_pass.pack(pady=1)
password_input = ctk.CTkEntry(app, width=300, placeholder_text="password")
password_input.pack()
submit_button = ctk.CTkButton(app, text="Encrypt",fg_color="green", command=submit_encrypt)
submit_button.pack(pady=10)
toggle_button = ctk.CTkButton(app, text="Switch Mode", command=switch_mode)
toggle_button.pack(pady=10)
success_label = ctk.CTkLabel(app, text="", font=("Arial", 16, "bold"))
success_label.pack(pady=0)
app.mainloop()