【问题标题】:Tkinter get() fails to return user input [duplicate]Tkinter get()无法返回用户输入[重复]
【发布时间】:2020-01-11 07:35:40
【问题描述】:

我正在开发一个使用 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()

【问题讨论】:

标签: python encryption tkinter tkinter-entry


【解决方案1】:

我没有复制你们所有的代码,但重点是您已将搜索指定为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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2021-10-05
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    相关资源
    最近更新 更多