
14

How to Get or Set Clipboard Text in Python
source link: https://jdhao.github.io/2021/02/03/get_or_set_system_clipboard_python/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Get or Set Clipboard Text in Python
2021-02-03103 words
1 min read
76 times read
There are several Python packages by which we can get and set the system clipboard.
Tkinter
Use tkinter to get clipboard text.
import tkinter as tk
root = tk.TK()
root.withdraw() # keep the window from showing
print(root.clipboard_get())
pywin32
Use pywin32. It provides the win32clipboard
module.
import win32clipboard
# set the clipboard
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText('just for a test')
win32clipboard.CloseClipboard()
# get the clipboard text
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
print(data)
win32clipboard.CloseClipboard()
pyperclip
Use pyperclip.
import pyperclip
# set the clipboard
pyperclip.copy('some text')
# get the clipboard
pyperclip.paste()
Reward
Using Proxy in Python Requests package
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK