Tkinter get() 无法 return 用户输入

Tkinter get() fails to return user input

我正在开发一个使用 GUI 加密 Linux 中文件的程序。这是我第一次创建和使用 GUI。
我在这里搜索过类似的问题,但没有找到可以帮助我的问题 当我在条目中键入并单击加密按钮时,由于我的 get 函数,我得到一个 AttributeError Nonetype。

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()

我没有复制你所有的代码,但关键是你已经将搜索指定为 Entry().place()Entry() 将具有 get() 属性。所以这会起作用。

search = Entry(root,width=45,bd=3)
search.place(x=50,y=75)

passw = Entry(root, width=33, show='*',bd=3)
passw.place(x=173,y=118)