How to copy a picture from canvas to clipboard? How to copy a picture from canvas to clipboard? tkinter tkinter

How to copy a picture from canvas to clipboard?


You could use .postscript method of the canvas to get an Encapsulated PostScript (EPS) representation of the contents. Then, use `ImageMagick's Python bindings (PythonMagick or PythonMagickWand) to convert the EPS to a Windows Enhanced Metafile (EMF). Finally, copy it to the clipboard (e.g. using nosklo's solution) with the CF_ENHMETAFILE clipboard format.


To use windows clipboard you must convert the image data to a format accepted by win api. Then, just use this function:

import win32clipboarddef send_to_clibboard(clip_type, data):     win32clipboard.OpenClipboard()    win32clipboard.EmptyClipboard()    win32clipboard.SetClipboardData(clip_type, data)     win32clipboard.CloseClipboard()

Where clip_type can be win32clipboard.CF_BITMAP, win32clipboard.CF_TIFF or many others.