Skip to content

Instantly share code, notes, and snippets.

@EBNull
Created September 4, 2012 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EBNull/3626441 to your computer and use it in GitHub Desktop.
Save EBNull/3626441 to your computer and use it in GitHub Desktop.
Copy / Retreive text to / from windows clipboard
def clipcopy(z):
#http://stackoverflow.com/questions/579687
z = unicode(z)
try:
import win32clipboard
except ImportError:
from Tkinter import Tk
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(z)
r.destroy()
else:
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(z)
win32clipboard.CloseClipboard()
def clipget():
import win32clipboard
win32clipboard.OpenClipboard()
cd = ''
if win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_TEXT):
cd = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
return cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment