How to copy a picture from canvas to clipboard?

前端 未结 2 895
刺人心
刺人心 2021-01-06 20:00

I have some Tkinter canvas and some picture of lines and text on it. Is there an easy way to copy it to a clipboard?

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 20:43

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

    import win32clipboard
    
    def 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.

提交回复
热议问题