I used this code to create an Encryptor in Tkinter.
The backend of the program on plain python is running as expected. When I use the Tkinter and create a form for password and the data to encrypt with the submit button, I use the Entry function of Tkinter for both password and the data to be entered. But when I use the .get()
function for storing the data in a variable and perform the encryption task I can't use the .get()
method as the .grid
or .pack()
both create the entry function to NoneType
, and when I use the .get()
function before I use the .grid()
or .pack()
the error is str type has no grid or pack function.
I am a beginner programmer and I don't know what is the problem with this, please help me.
The Code is:
from tkinter import *
root = Tk()
root.title("Encryptor")
def encrypt(sentence, key):
asc_sentence = []
asc_key = []
encryp = []
encrypted = ""
for letter in key:
le = ord(letter) - 17
asc_key.append(le)
asc_sum = sum(asc_key)
for letter in sentence:
lex = ord(letter) + asc_sum
asc_sentence.append(lex)
for i in asc_sentence:
lconv = chr(i)
encryp.append(lconv)
for index in encryp:
encrypted += index
enc = Label(root, textvariable=encrypted)
enc.pack()
def input_enc():
intro = Label(root, text="------------------------- Encrypt your Data----------------------")
intro.pack()
pwd_l = Label(root, text="Enter your Key to encrypt the data: ")
pwd_l.pack()
password = Entry(root, width=25).pack()
data_l = Label(root, text="Input the data You want to Encrypt: ")
data_l.pack()
data = Entry(root, width=25).pack()
edata = data.get()
epwd = password.get()
submit = Button(root, text="Encrypt", command=lambda: encrypt(edata, epwd))
submit.pack()
input_enc()
root.mainloop()
The Error is:
Traceback (most recent call last):
File "/home/lord_hendrix17/PycharmProjects/P0/main.py", line 46, in <module>
input_enc()
File "/home/lord_hendrix17/PycharmProjects/P0/main.py", line 41, in input_enc
edata = data.get()
AttributeError: 'NoneType' object has no attribute 'get'
Process finished with exit code 1