'How to copy file from a folder to clipboard using tkinter?

I have the path to a file, will usually be an image or a video, and I would like to copy this file to the clipboard so I can paste it somewhere else, eg: another folder, websites etc.

Disappointingly, the following doesn't work

loc="C:/Path/To/File"
root.clipboard_clear()
root.clipboard_append(loc)

even though if I ctrl + C the file and print self.parent.clipboard_get(), I get loc

How can I achieve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source