Mar-19-2019, 07:11 AM
Kubuntu 18.10x64, Python 3.7.2
I used two ways to add text to the clipboard and in both of them the data can be read from the clipboard only within the Python program. It is impossible to insert data into an external text- file using the 'ctrl + v' combination or the mouse menu.
The pyperclip module works well, but requires the installation of additional libraries for Linux (which makes it difficult to migrate / reinstall the system): GitHub
I used two ways to add text to the clipboard and in both of them the data can be read from the clipboard only within the Python program. It is impossible to insert data into an external text- file using the 'ctrl + v' combination or the mouse menu.
import tkinter c = tkinter.Tk() c.withdraw() c.clipboard_clear() c.clipboard_append('sample text') #text_value = c.clipboard_get()
from PyQt5 import QtWidgets,QtCore from PyQt5.QtGui import QClipboard q_app = QtWidgets.QApplication(sys.argv) clipboard = q_app.clipboard() text_function = 'sample text' clipboard.clear(mode=QClipboard.Clipboard) clipboard.setText(text_function, mode=QClipboard.Clipboard) #added on the advice from here: https://stackoverflow.com/questions/1073550/pyqt-clipboard-doesnt-copy-to-system-clipboard event = QtCore.QEvent(QtCore.QEvent.Clipboard) q_app.sendEvent(clipboard, event) #text_value = clipboard.text(mode=QClipboard.Clipboard)How can I read data from the clipboard in an external program?
The pyperclip module works well, but requires the installation of additional libraries for Linux (which makes it difficult to migrate / reinstall the system): GitHub
import pyperclip pyperclip.copy('The text to be copied to the clipboard.')