For my course I was introduced in the XOR operator within Python. We had to decrypt a string. Works all good. Now it got me started to create my own script, with a pop up window, asking for a key, followed by a string and eventually a window that shows the result.
Now thats all working as intended (doesnt look super fly, but it works!) but the result in the last window is text that cannot be copied. Now I would like that the result CAN be copied so you could throw it back in the script to en/decrypt again.
Is this possible?
The code:
import tkinter as tk, sys, tkinter.messagebox
from tkinter import simpledialog
ROOT = tk.Tk()
ROOT.withdraw()
my_secret_key = simpledialog.askstring(title="Key",
prompt="Whats your secret key?:")
Text = simpledialog.askstring(title="Translator",
prompt="What would you like to encrypt or decrypt?:")
while True:
def decrypt(secret_string, secret_number):
result = ""
for x in secret_string:
result = result + chr(ord(x) ^ int(secret_number))
return result
Text = tkinter.messagebox.showinfo(title="Answer",
message=(decrypt(Text, my_secret_key)))
sys.exit()
I havent really tried anything other than looking for options to get this into the script. I found possible ways to add a copy button, but this hasn't worked so far. This code i added was :
def copyToClipboard():
val = clickedWidget.selection_get()
root.clipboard_clear()
root.clipboard_append(val)
But I really just want to be able to rightclick/mouse select the text to be copied. Is that possible?