Pasting an image from clipboard in Tkinter?

exhuma.twn exhuma at
Mon Jun 11 14:23:48 CEST 2007

As many might know, windows allows to copy an image into the clipboard
by pressing the "Print Screen" button on the keyboard. Is it possible
to paste such an image from the clipboard into a "Text" widget in
Tkinter? Here is my first attempt with just trying to print out the
image data:

def pasteImg(tgt):
   global clipboardEnabled
   if not clipboardEnabled: return

   print win32clipboard.GetClipboardData()

This works fine with selecting text, but comes up with the following
error when trying to paste an image:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python25\lib\lib-tk\", line 1403, in __call__
    return self.func(*args)
  File "X:\development\testing\tkwiki\", line 52, in <lambda>
    Button( root, command=lambda: pasteImg(txt) ).pack()
  File "X:\development\testing\tkwiki\", line 38, in pasteImg
    print win32clipboard.GetClipboardData()
TypeError: Specified clipboard format is not available

Obviously the clipboard does not know about that format. Does that
mean I have to wait until it's implemented or are there other ways to
access the image data?

More information about the Python-list mailing list