So first a little disclaimer: I'm pretty to new to programming in general and i have alot to learn. so my code will probably seem very sloppy and ridiculous. So i am sorry for that.
I am trying to make a simple gui program that takes text entered by the user and turns it into gibberish from a dictionary i made. So with this you can encrypt and decrypt text. this is the console script i made:
`list = {"a": "l", "b": "k", "c": "j", "d": "h", "e": "g", "f": "d", "g": "f", "h": "d", "i": "s", "j": "a", "k": "q", "l": "w", "m": "e", "n": "r", "o": "t", "p": "y", "q": "u", "r": "z", "s": "x", "t": "c", "u": "m", "v": "n", "w": "p", "x": "b", "y": "i", "z": "o", " ": " "}
list_2 = {"l": "a", "k": "b", "j": "c", "h": "d", "g": "e", "d": "f", "f": "g", "d": "h", "s": "i", "a": "j", "q": "k", "w": "l", "e": "m", "r": "n", "t": "o", "y": "p", "u": "q", "z": "r", "x": "s", "c": "t", "m": "u", "n": "v", "p": "w", "b": "x", "i": "y", "o": "z", " ": " "}
def encrypt():
user_input = raw_input("what is the messge?:\n")
for char in user_input:
print list[char.lower()],
def decrypt():
user_input = raw_input("what is the messge?:\n")
for char in user_input:
print list_2[char.lower()],
which_one = raw_input("type 1 for encrypt, type 2 for decrypt:\n")
if which_one == "1":
encrypt()
elif which_one == "2":
decrypt()
else:
print "ERROR!"
`
so now I'm trying to implement the same idea but with a gui using tkinter. Where I'm stuck is trying to basically print what the result is somewhere. This is what i have so far:
from Tkinter import *
list = {"a": "l", "b": "k", "c": "j", "d": "h", "e": "g", "f": "d", "g": "f", "h": "d", "i": "s", "j": "a", "k": "q", "l": "w", "m": "e", "n": "r", "o": "t", "p": "y", "q": "u", "r": "z", "s": "x", "t": "c", "u": "m", "v": "n", "w": "p", "x": "b", "y": "i", "z": "o", " ": " "}
list_2 = {"l": "a", "k": "b", "j": "c", "h": "d", "g": "e", "d": "f", "f": "g", "d": "h", "s": "i", "a": "j", "q": "k", "w": "l", "e": "m", "r": "n", "t": "o", "y": "p", "u": "q", "z": "r", "x": "s", "c": "t", "m": "u", "n": "v", "p": "w", "b": "x", "i": "y", "o": "z", " ": " "}
root = Tk()
encrypt_entry_var = StringVar()
decrypt_entry_var = StringVar()
def encrypt(encrypt_entry_var):
for char in encrypt_entry_var:
return list
results = encrypt(encrypt_entry_var)
results_label = Label(root, str(results))
encrypt_entry = Entry(root, textvariable=encrypt_entry_var)
encrypt_button = Button(root, text="Encrypt", command=encrypt)
decrypt_entry = Entry(root, textvariable=decrypt_entry_var)
decrypt_button = Button(root, text="Decrypt")
encrypt_entry.pack(fill=X)
encrypt_button.pack(fill=X)
decrypt_entry.pack(fill=X)
decrypt_button.pack(fill=X)
root.title("Encryption Chat")
root.geometry("500x90")
mainloop()
This is the error i get:
Current directory: C:\Users\Cody Pickett\Desktop\Coding\current projects
C:\Python27\python.exe -u "C:\Users\Cody Pickett\Desktop\Coding\current projects\Encrypyion_chat_wgui.py
Process started >>>
Traceback (most recent call last):
File "C:\Users\Cody Pickett\Desktop\Coding\current projects\Encrypyion_chat_wgui.py", line 15, in <module>
results = encrypt(encrypt_entry_var)
File "C:\Users\Cody Pickett\Desktop\Coding\current projects\Encrypyion_chat_wgui.py", line 12, in encrypt
for char in encrypt_entry_var:
TypeError: iteration over non-sequence
<<< Process finished. (Exit code 1)
================ READY ================
Any help would be very appreciated.I hope i gave enough information to help you understand. Thank you all for your time and have a nice day!!!
Update: so now this is the error im getting:
Process started >>>
Traceback (most recent call last):
File "C:\Users\Cody Pickett\Desktop\Coding\current projects\Encrypyion_chat_wgui.py", line 21, in <module>
encrypt_button = Button(root, text="Encrypt", command=encrypt(encrypt_entry_var))
File "C:\Users\Cody Pickett\Desktop\Coding\current projects\Encrypyion_chat_wgui.py", line 12, in encrypt
for char in encrypt_entry_var:
TypeError: iteration over non-sequence
<<< Process finished. (Exit code 1)
================ READY ================
I do not understand what iteration over non-sequence exactly means. I could not wrap my head around what google had to say about it. I've never had this error in previous projects.
Updated code:
from Tkinter import *
list = {"a": "l", "b": "k", "c": "j", "d": "h", "e": "g", "f": "d", "g": "f", "h": "d", "i": "s", "j": "a", "k": "q", "l": "w", "m": "e", "n": "r", "o": "t", "p": "y", "q": "u", "r": "z", "s": "x", "t": "c", "u": "m", "v": "n", "w": "p", "x": "b", "y": "i", "z": "o", " ": " "}
list_2 = {"l": "a", "k": "b", "j": "c", "h": "d", "g": "e", "d": "f", "f": "g", "d": "h", "s": "i", "a": "j", "q": "k", "w": "l", "e": "m", "r": "n", "t": "o", "y": "p", "u": "q", "z": "r", "x": "s", "c": "t", "m": "u", "n": "v", "p": "w", "b": "x", "i": "y", "o": "z", " ": " "}
root = Tk()
encrypt_entry_var = StringVar()
decrypt_entry_var = StringVar()
def encrypt(encrypt_entry_var):
for char in encrypt_entry_var:
return list
results = encrypt(encrypt_entry_var.get())
results_label = Label(root, text=str(results))
encrypt_entry = Entry(root, textvariable=encrypt_entry_var)
encrypt_button = Button(root, text="Encrypt", command=encrypt(encrypt_entry_var))
decrypt_entry = Entry(root, textvariable=decrypt_entry_var)
decrypt_button = Button(root, text="Decrypt")
encrypt_entry.pack(fill=X)
encrypt_button.pack(fill=X)
decrypt_entry.pack(fill=X)
decrypt_button.pack(fill=X)
results_label.pack
root.title("Encryption Chat")
root.geometry("500x90")
mainloop()