Reading Text from the Windows Clipboard in Python
To retrieve text from the Windows clipboard in Python, leverage the win32clipboard module within PyWin32.
Example:
<code class="python">import win32clipboard # Set the clipboard data win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText('testing 123') win32clipboard.CloseClipboard() # Retrieve the clipboard data win32clipboard.OpenClipboard() data = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() print(data)</code>
Important Reminder:
Ensure you close the clipboard after interacting with it using the CloseClipboard function. This allows other applications to access the clipboard. Avoid adding new data after closing it.
The above is the detailed content of How can I retrieve text from the Windows clipboard using Python?. For more information, please follow other related articles on the PHP Chinese website!