Saturday, March 25, 2017

Python: copy paste buffer

Seems like PyQt4 is the ideal way to go:

Two styles:
##how to get something into the clipboard / copy/paste buffer
from PyQt4 import QtGui
QtGui.QApplication.clipboard().setText(textString)

##and to get it back out
text = QtGui.QApplication.clipboard().text()

##but it will be a QString so you'll probably want to 
textString = str(text)


In some cases PyQt4 seems to be crippled, so you can also use Tkinter, which seems to work well for extracting from clipboard. Haven't had luck putting stuff in though:
import Tkinter
root = Tkinter.Tk()
root.withdraw() # Hide the main window (optional)
rawClip = root.clipboard_get()

No comments :

Post a Comment