Accessing text copied to clipboard by python Accessing text copied to clipboard by python tkinter tkinter

Accessing text copied to clipboard by python


If you don't use the clipboard content before your script ends, it is discarded. Keep it running until you no longer need the clipboard content. The following program will keep '1234' in the clipboard for 10 seconds. If you don't paste it within that time, it is lost. If you do paste it within that time, it will remain in the clipboard even after the program ends.

import tkinter as tkr = tk.Tk()r.withdraw()r.clipboard_clear()r.clipboard_append('1234')r.after(10000, lambda: r.destroy())r.mainloop()


How do I read text from the (windows) clipboard from python?

"Worth noting, in py34, win7, SetClipboardText did not work without a preceding call to EmptyClipboard"

import win32clipboard# set clipboard datawin32clipboard.OpenClipboard()win32clipboard.SetClipboardText('testing 123')win32clipboard.CloseClipboard()# get clipboard datawin32clipboard.OpenClipboard()data = win32clipboard.GetClipboardData()win32clipboard.CloseClipboard()print data