Hallo,
ich habe folgendes programmiert:
import tkinter as tk
import os
root = tk.Tk()
root.geometry("400x240")
def encrypt(filename):
to_encrypt = open(filename, "rb").read()
size = len(to_encrypt)
key = os.urandom(size)
with open(filename + ".lqk", "wb") as key_out:
key_out.write(key)
encrypted = bytes(a ^ b for (a, b) in zip(to_encrypt, key))
with open(filename, "wb") as encrypted_out:
encrypted_out.write(encrypted)
filename = textExample.get(1.0, tk.END+"-1c")
encrypt(filename)
def decrypt(filename, key):
file = open(filename, "rb").read()
key = open(key, "rb").read()
decrypted = bytes(a ^ b for (a, b) in zip(file, key))
with open(filename, "wb") as decrypted_out:
decrypted_out.write(decrypted)
fileTest = filename + ".lqk"
try:
os.remove(fileTest)
except OSError as e:
print(e)
else:
print("Datei erfolgreich gelöscht!")
filename = textExample.get(1.0, tk.END+"-1c")
decrypt(filename, filename + ".lqk")
textExample=tk.Text(root, height=10)
textExample.pack()
btnEncrypt=tk.Button(root, height=1, width=10, text="Encrypt",
command=encrypt)
btnDecrypt=tk.Button(root, height=1, width=10, text="Decrypt",
command=decrypt)
btnEncrypt.pack()
btnDecrypt.pack()
root.mainloop()
Nur leider funktioniert dies nicht. In der Debugging Console bekomme ich folgende Fehlermeldung:
Bei der Encrypt Funktion:
PS C:\Users\elias\Desktop\Python> c:; cd 'c:\Users\elias\Desktop\Python'; & 'C:\Users\elias\AppData\Local\Programs\Python\Python310\python.exe' 'c:\Users\elias\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy\launcher' '52518' '--' 'c:\Users\elias\Desktop\Python\main.py'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\elias\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
TypeError: encrypt() missing 1 required positional argument: 'filename'
Decrypt Funktion:
Traceback (most recent call last):
File "C:\Users\elias\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
TypeError: decrypt() missing 2 required positional arguments: 'filename' and 'key'
Wie kann ich das Problem jetzt lösen?
Danke im Vorraus!
VG!