Python Forum
I can't read data from the clipboard in an external program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I can't read data from the clipboard in an external program
#1
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.

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.')
Reply
#2
I would definitely go with pyperclip. Don't remember any issues with installing on linux mint
Even if some dependencies need to be installed as long as it is clearly stated in the documentation of your product there should be no problems
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 318 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  non-latin characters in console from clipboard Johanson 3 656 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  Correctly read a malformed CSV file data klllmmm 2 1,814 Jan-25-2023, 04:12 PM
Last Post: klllmmm
  data file for .exe program to access ose 2 1,145 Nov-23-2022, 08:02 PM
Last Post: snippsat
  Read nested data from JSON - Getting an error marlonbown 5 1,310 Nov-23-2022, 03:51 PM
Last Post: snippsat
  I have written a program that outputs data based on GPS signal kalle 1 1,134 Jul-22-2022, 12:10 AM
Last Post: mcmxl22
  Read data via bluetooth frohr 9 3,152 Jul-10-2022, 09:51 AM
Last Post: frohr
  Write and read back data Aggie64 6 1,812 Apr-18-2022, 03:23 PM
Last Post: bowlofred
  saving and loading text from the clipboard with python program MaartenRo 2 1,622 Jan-22-2022, 05:04 AM
Last Post: MaartenRo
  How to read rainfall time series and insert missing data points MadsM 4 2,124 Jan-06-2022, 10:39 AM
Last Post: amdi40

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020