Q:

Create Copy and Paste function with Python

I am looking for a solution to add a function to a program using Python. I want to copy and paste selected data (selected with the mouse).
Example:

Copy "Hello" using CTRL-C from the sentence "Hello everybody" when I select Hello.          
Copy a part of array selected using CTRL-C

My main problem is how to use the selected data.  But now I just can copy string defined in the code (here "tt"):
clipboard.OpenClipboard()
clipboard.EmptyClipboard()
clipboard.SetClipboardText('tt')
clipboard.CloseClipboard()

I tried several codes found on the internet and in this website but none of them fixed my problem.

A:

You don't need to call clipboard.SetClipboardText(). When a program supports the clipboard, then Ctrl+C will copy the currently selected text into the clipboard. There is nothing you need to do to make this happen.
If your question is "How can I trigger Ctrl+C from outside of a program to copy the currently selected text into the clipboard", then the answer is: Usually, you can't. For security reasons, most programs don't respond to artificial key events which other programs send them.
The second error is something else entirely. Your class CopyEvent doesn't have a property list, so Python can't invoke methods in it.

