Encryption of SHA1 algorithm with Tkinter

1

Hi, I'm doing an SHA-1 algorithm exercise with Python 3.4 and Tkinter

My problem is that I do not know how to show the result of the conversion of my caja1 to the caja2 . Here is the code:

 from tkinter import *
 from hashlib import sha1


 def encriptar():
     sha1(texto).hexdigest()


 ventana = Tk()
 ventana.geometry("600x320")

 texto = StringVar()
 texto_encriptado = StringVar()


 caja1 = Entry(ventana, textvariable=texto).place(x=150, y=50)


 botonEncriptar = Button(ventana, text="Encriptar", command=encriptar).place(x=150, y=100)

 caja2 = Entry(ventana, textvariable=texto_encriptado, width=40).place(x=150, y=200)

 ventana.mainloop()
    
asked by Andres Vilca 02.04.2016 в 19:20
source

1 answer

3

The problem is that you have to pass a text string to the sha1 function, but you are passing it an instance of Tkinter.StringVar , what you need is to get the text and then set the text of the caja2 .

Your function would look like this:

def encriptar():
    encriptado = sha1(texto.get()).hexdigest()
    texto_encriptado.set(encriptado)

Since you're working with Python 3.x, you need to use encode before encrypting:

def encriptar():
    encriptado = sha1(texto.get().encode('utf-8')).hexdigest()
    texto_encriptado.set(encriptado)

And the rest would be something like this:

    
answered by 04.04.2016 в 14:32