0

I'm trying to understand how I can get a program to copy a given text to the system clipboard and then be able to paste that text to any other application systemwide.

I have designed a GUI with Glade and have a GtkEntry and a Button to copy the text, everything works well GUI-wise except I can't get the text in GtkEntry to be copied to the system clipboard when I click the copy button and therefore I am not able to paste it anywhere else.

Here is a bit of the code that I wrote in Python 3.6

def on_copy_Button_clicked(self, button, data=None):
    text_Field = builder.get_object("text_Field")
    text_Field = str(text_Field.get_text())
    pyperclip.copy(text_Field)

Copy comment:

Traceback (most recent call last): 
File "/home/vittorio/Self-made_programs/Python/Simple Copy-Paste/simple copy-paste.py", line 17, 
    in on_copy_Button_clicked pyperclip.copy(text_Field) 
File "/usr/local/lib/python3.6/dist-packages/pyperclip/__init__.py", line 616, 
    in lazy_load_stub_copy return copy(text) 
File "/usr/local/lib/python3.6/dist-packages/pyperclip/__init__.py", line 150,
    in copy_gtk cb = gtk.Clipboard() 
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 69, 
    in getattr raise AttributeError(_static_binding_error)
stovfl
  • 14,998
  • 7
  • 24
  • 51
  • What gets printed if you do `pyperclip.paste()` ? – Alan Kavanagh Nov 06 '19 at 21:31
  • Have you verified that `text_Field` holds what you expected? – stovfl Nov 06 '19 at 22:52
  • Ok so I managed to sort this out by following this guide 'https://python-gtk-3-tutorial.readthedocs.io/en/latest/clipboard.html' only thing now is I'm trying to apply the same thing instead of using a GtkEntry, using a GtkTextView.. – Vittorio Basile Nov 08 '19 at 00:19

0 Answers0