Social Widget

Responsive Ads Here

Friday, January 3, 2020

copy text to clipboard and paste text from clipboard using python

We deal with copying and pasting text every day. But what if we could copy a text to the clipboard or paste the copied text from the clipboard to the terminal using python?

This can be achieved using a python library called pyperclip.


Pyperclip is a cross-platform Python module for copy and paste clipboard functions. It works with Python 2 and 3.

pip install pyperclip

The above command installs the pyperclip library on your device.


1. First import the package.

import pyperclip

2. Copy text to the clipboard.


This copies the text "codesimple" to your clipboard. If you "CTRL + V " on your notepad, you can see that the text "codesimple" appears there. 

3. Paste text from clipboard to terminal or access it in the python program.

Copy some random text using "CTRL + V". This will be copied to our clipboard. Go to the terminal and import pyperclip package. Then enter the following command.

we can see that our copied text is being printed on the terminal. 

#pyperclip #python #copy #paste #clipboard 

No comments:

Post a Comment