Copy file contents to clipboard in Windows

1
Hello, I am making a software for a forum, where members consult the posting patterns by the software, I am storing these patterns in files and asking Python to read those files and display them, so the user copies the pattern.

Now I want to ask Python to copy the contents of the default file to the Clipboard (which is the copy and paste). So not needing the user to select the text and copy, I want the software to do it myself, but how do I do it? I researched a lot and did not find it.

I will leave a print of the data output that I want to copy to the (copy Windows paste). Ignore the other tags.

data output http://www.imgfans.com.br/i777/SirGates/erro. png

    
asked by anonymous 23.03.2015 / 15:08

2 answers

1

I've used this code:

import clipboard

clipboard.paste() 
with open('teste.txt', 'r') as f:
     conteudo = f.read()     
     clipboard.copy(conteudo)

I followed this video to install Clipboard.

In the video, you then in DOS and enter C: / PythonXX / Scripts and the command pip install clipboard

    
23.03.2015 / 17:41
2

For Windows you can use the module win32clipboard , if you prefer an alternative < cross-platform , pyperclip module.

Example of using win32clipboard module (not tested):

import win32clipboard

win32clipboard.OpenClipboard()

with open('arquivo', 'r') as f:
   conteudo = f.readlines()
   win32clipboard.SetClipboardText(conteudo)
win32clipboard.CloseClipboard()
    
23.03.2015 / 15:43