How to Copy Text to Clipboard in Python

To copy text to the clipboard in Python, use the pyperclip module.

Before you can use the module, you need to install it with:

pip install pyperclip

Then you can use its copy() method to copy text to the clipboard by:

import pyperclip

s1 = "Hello world"

pyperclip.copy(s1)

s2 = pyperclip.paste()

print(s2)

Output:

Hello world

Conclusion

Thanks for reading. I hope you found what you were looking for.

Happy coding!

Further Reading

Python Tricks

How to Write to a File in Python

The with Statement in Python

Share on facebook
Share on twitter
Share on linkedin

Leave a Comment

Your email address will not be published.