tkinter error when copying contents from clipboard in Python tkinter error when copying contents from clipboard in Python tkinter tkinter

tkinter error when copying contents from clipboard in Python


You can't avoid the error since this is designed behavior, but you can handle the error.

import tkinter as tk...try:    selection = r.selection.get(selection="CLIPBOARD")except tk.TclError:    selection = None...


I came across with the below script and it helped me to get what I aimed for.

import timefrom tkinter import Tkwhile True:    r = Tk()    try:        result = r.selection_get(selection="CLIPBOARD")        print(result)        time.sleep(1)    except:        selection = None

I went on with having the try except block with a generic except. @Bryan Oakley's suggestion helped a lot.