Copy from clipboard using Python and Tkinter Copy from clipboard using Python and Tkinter tkinter tkinter

Copy from clipboard using Python and Tkinter


Using Tkinter, I would use a try..except block to insert the clipboard data where it exists and ignore it where it doesn't (or, optionally, add some default value). This doesn't specifically revoke any image-type clipboard contents, but it will reject anything that isn't in myTkObject.clipboard_get()'s expected format. That's a string by default, though you can change it with the function's type keyword argument.

Here's an example that builds on Nodak and jonrsharpe's answer and comments:

from Tkinter import TkmyTkObject = Tk()try:    listbox.insert(0, myTkObject.clipboard_get())except Tkinter.TclError:    pass  # Instead of do-nothing, you can insert some default value if you like.