How to clear clipboard in using python?

Question:

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

Asked By: user2651231

||

Answers:

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

Answered By: 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.

Answered By: Priyank Chheda

Selected answer may not be sufficient as Windows 10 onwards has Clipboard history (optional, Win key + V), so copying "" won’t delete past copies which defeats the purpose.

Answered By: Ace
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.