I'm working on a program that encrypts files in Linux using a GUI. It's the first time I'm creating and using GUIs.
I've searched similar questions here but I didn't find what can help me
When I type inside the entry and click the encrypt button I get an AttributeError Nonetype because of my get function.
import os, random
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
from tkinter import *
from PIL import Image, ImageTk
def encrypt(key,filename):
chunksize = 64*1024
outputFile = "(criptat)"+filename
filesize = str(os.path.getsize(filename)).zfill(16)
IV = ''
for i in range(16):
IV += chr(random.randint(0, 0xFF))
encryptor = AES.new(key,AES.MODE_CBC, IV)
with open(filename, 'rb') as infile:
with open(outputFile, 'wb') as outfile:
outfile.write(filesize)
outfile.write(IV)
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += ' ' * (16 - (len(chunk) % 16))
outfile.write(encryptor.encrypt(chunk))
def decrypt(key,filename):
chunksize = 64*1024
outputFile = filename[11:]
with open(filename, 'rb') as infile:
filesize = long(infile.read(16))
IV = infile.read(16)
decryptor = AES.new(key, AES.MODE_CBC, IV)
with open(outputFile, 'wb') as outfile:
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
outfile.write(decryptor.decrypt(chunk))
outfile.truncate(filesize)
def getKey(password):
hasher = SHA256.new(password)
return hasher.digest()
# Main Win Options
# --------------
root = Tk()
root.title("EncryptionGUI")
root.minsize(600,500)
root.maxsize(600,500)
c2 =" CL"
canvas = Canvas(root, width=600, height=500)
canvas.place(x=0, y=0)
# Widgets
# --------------
search = Entry(root,width=45,bd=3).place(x=50,y=75)
status = Entry(root,width=25,bd=3,bg="#CFB6B6")
status.insert(END,"############################################")
status.place(x=50,y=385)
passw = Entry(root, width=33, show='*',bd=3).place(x=173,y=118)
def cript():
filen = search.get()
passfile = passw.get()
encrypt(getKey(passfile), filen)
#def decript():
#filen = search.get()
#passfile = passw.get()
#decrypt(getKey(passfile), filen)
# Labels
# --------------
File_Name_text = Label(root, text="File Name",bg="#C7D2D8", font=("Verdana",10,"bold")).place(x=50,y=35)
Status_text = Label(root, text="File Status",bg="#CFB6B6", font=("Helvetica",10,"bold")).place(x=50,y=350)
Password_text = Label(root, text="Password :",bg="#C7D2D8", font=("Verdana",10,"bold")).place(x=50,y=115)
cr = Label(root, text=c2,bg="#C7D2D8", font=("Helvetica",12)).place(x=450,y=475)
#Buttons
# --------------
Buton_Criptare = Button(root, text="Encrypt",bg="#DF2C2C", anchor=CENTER, font=("Helvetica",17,"bold"), activebackground="#FF0000", command=cript).place(x=150,y=175)
Buton_Decriptare = Button(root, text="Decrypt",bg="#B9FF8E", anchor=CENTER, font=("Helvetica",17,"bold"), activebackground="#46FF00").place(x=300,y=175)
# Other Things
# --------------
root.mainloop()