0

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
Ajit Panigrahi
  • 752
  • 10
  • 27

1 Answers1

0
from tkinter import *

root = Tk()
root.title("Encryptor")


def encrypt(sentence, key):
    #print(sentence)
    #print(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():
    edata=StringVar()#!!!
    epwd=StringVar()#!!!
    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, textvariable=epwd,width=25).pack()#!!!
    data_l = Label(root, text="Input the data You want to Encrypt: ")
    data_l.pack()
    data = Entry(root, textvariable=edata,width=25).pack()#!!!
    #edata = data.get()
    #epwd = password.get()
    submit = Button(root, text="Encrypt", command=lambda: encrypt(edata.get(), epwd.get()))#!!!
    submit.pack()

input_enc()
root.mainloop()

see the changes in code

virxen
  • 408
  • 4
  • 12
  • 1
    Code-only answers aren't very useful, because it requires us to compare your code to the original line-by-line and character-by-character. This answer would be better if you included a short description of what you changed. – Bryan Oakley Feb 08 '20 at 14:25
  • All the changes i have made have a #!! at the end.I will try better next time,thank you. – virxen Feb 08 '20 at 17:26