From 90c889fb77114bb14c65ea4834015f5ea46b3416 Mon Sep 17 00:00:00 2001 From: Sekun Date: Tue, 13 Aug 2024 00:05:41 +0200 Subject: [PATCH] Clear clipboard after closing window. --- prog/tqr.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/prog/tqr.py b/prog/tqr.py index 6099b87..167411f 100644 --- a/prog/tqr.py +++ b/prog/tqr.py @@ -27,7 +27,12 @@ def main(): root = tk.Tk() root.title = "Qr code" 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: code = qr.create(data) except ValueError as e: @@ -47,6 +52,13 @@ def main(): img.config(background="white") label = tk.Label(root, image=img) label.pack() + + def empty_clipboard(): + root.clipboard_clear() + root.destroy() + + root.protocol("WM_DELETE_WINDOW", empty_clipboard) + root.mainloop()