It is my first tkinter GUI app in python, I got errors. So pls help.
Dont rename the variables as much as you can pls. I used many resources so it may be hard to understand some codes.
class app (Frame):
root=Tk()
def __init__(self):
main_win = tk.Frame.__init__(self)
self.master.title("encryption and decryption app")
main_win.txt_box = Text(Tk(), hieght=2, width=10)
main_win.txt_box.pack()
main_win.passw_box = Text(root, hieght=2, width=10)
main_win.passw_box.pack()
def encrypt(self):
data = self.txt_box.get("1.0", END)
password = self.passw_box.get("1.0", END)
encrypted_text = ""
for i in range(len(data)):
new = chr(abs(ord(password[(i % len(password))]) + ord(data[i])))
encrypted_text = encrypted_text + new
tkinter.messagebox.showinfo("encrypted text in utf-8",encrypted_text)
def decrypt (self):
data = self.txt_box.get("1.0", END)
password = self.passw_box.get("1.0", END)
decrypted_text = ""
for i in range(len(data)):
new = chr(abs(ord(password[(i % len(password))]) - ord(data[i])))
decrypted_text = decrypted_text + new
tkinter.messagebox.showinfo("decrypted text in utf-8",decrypted_text)
main_win.en_button = tk.Button(self, text = "encrypt", width = 25,command = encrypt(main_win))
main_win.de_button = tk.Button(self, text="decrypt", width=25, command= decrypt(main_win))
def main():
app().mainloop()
if __name__ == '__main__':
main()
I expext to get an app that decrypt and encrypt text. Note that the encrypt and decrypt functions needs a password and text.