Clear clipboard after closing window.

This commit is contained in:
Sekun 2024-08-13 00:05:41 +02:00
parent 908a10a37f
commit 90c889fb77

View file

@ -27,7 +27,12 @@ def main():
root = tk.Tk() root = tk.Tk()
root.title = "Qr code" root.title = "Qr code"
root.state("iconic") root.state("iconic")
data = root.clipboard_get() try:
data = root.clipboard_get()
except Exception as e:
messagebox.showerror("Qr code", f"Cannot get content of clipboard.\n«{e}»")
exit(1)
try: try:
code = qr.create(data) code = qr.create(data)
except ValueError as e: except ValueError as e:
@ -47,6 +52,13 @@ def main():
img.config(background="white") img.config(background="white")
label = tk.Label(root, image=img) label = tk.Label(root, image=img)
label.pack() label.pack()
def empty_clipboard():
root.clipboard_clear()
root.destroy()
root.protocol("WM_DELETE_WINDOW", empty_clipboard)
root.mainloop() root.mainloop()