Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear clipboard in using python?

I want to clear my clipboard after copying stuff. Is this possible?

I tried using clipboard and paperclip, but they don't have clear methods. https://pypi.org/project/pyperclip/#description

like image 697
user2651231 Avatar asked Dec 02 '25 05:12

user2651231


2 Answers

You can just copy an empty string: pyperclip.copy('')

like image 114
vencaslac Avatar answered Dec 04 '25 02:12

vencaslac


If you are on Windows

from ctypes import windll
if windll.user32.OpenClipboard(None):
    windll.user32.EmptyClipboard()
    windll.user32.CloseClipboard()

No external libraries needed.

like image 24
Priyank Chheda Avatar answered Dec 04 '25 02:12

Priyank Chheda