[Image-SIG] PIL ImageGrab clipboard block

Ole Trenner ole.trenner at gmx.de
Sat Apr 14 18:32:22 CEST 2007

Hi List,

I'm currently using the ImageGrab module of PIL for a small image upload 
client. I've noticed that the ImageGrab.grabclipboard() method seems to 
somehow block the clipboard. I'll try to explain:

This is what works: When the Windows clipboard contains image data when 
first trying to use ImageGrab.grabclipboard() it works as supposed. You 
can further change the clipboard contents (copy image data from another 
application) and reinvoke ImageGrab.grabclipboard() to fetch the new data.

And this is what doesn't work: When the windows clipboard contains text 
  (or nothing) when trying to use ImageGrab.grabclipboard(), any 
subsequent calls to ImageGrab.grabclipboard() fail. AND it seems as if 
the clipboard was blocked, i.e. none of my graphical apps is able to 
copy image data to the clipboard until my upload client is finished.

This minimal loop can be used to test the behavior:

import Image, ImageGrab
while True:
     img = ImageGrab.grabclipboard()
     if isinstance(img, Image.Image):
         print "Found Image"
         print "No Image"
     print "Press Enter to continue...",

I'd love to see a way to "reset" the clipboard or fix my app to be able 
to paste image data even if the clipboard was empty or just contained 
text on startup.

Thanks in advance,
Ole Trenner

More information about the Image-SIG mailing list