![]() I may even use a Notebook Widget, so that multiple hash values, together with the file names, are inserted into said Widget and from which they can be either copied in the usual way, or even written to a file.Įdit: yes, Tkinter is the GUI interface I’m using, as it comes with all (I think) Python installs. My untidy work around is to have a button that switches the widget state back to ‘normal’ so that the hash value can then be ‘copied’ to the clipboard in the usual way. Thanks for your time and the link that you’ve provided (that’s a very interesting read and I’ll squirrel that away as I’m sure it will come in handy). I was hoping that there could be some redirection of the standard output that I could use, so instead of the print() function going to the screen, it could be redirected to the system clipboard, but if only it were that simple, right? I was kinda thinking that if it were as simple to do as it is to type, then I’d have either been aware of it or I’d have found it by now. In fact, my intention is to release this app into the public domain and as such, I need it to be as “friendly” as it can be. What GUI framework are you using? If it is Tkinter, this may work for you: How to make menubar cut/copy/paste with Python/Tkinter String Literals Typing string values in Python code is fairly straightforward: they begin and end with a single quote. Working with Strings Let’s look at some of the ways Python lets you write, print, and access strings in your code. There is, allegedly, at least two others: pyperclip3 and clipboard.įinally, your GUI framework may already support copy and paste out of the box. You can even write Python code to access the clipboard for copying and pasting text. ![]() If you are sure that this app of yours is only for personal use and won’t be used by people on other flavours of Linux, or MacOS, or Windows, or other non-Linux unixes and POSIX systems, then you could copy the relevant code from pyperclip into your own project and use that instead.Īnd then be prepared to deal with bugs in copy/pasting yourself.īut if you expect to distribute this app to others, you will be better off using the external dependency (assuming the licence is suitable).Īlternatively, you could try a different copy/paste library. So to get copy and pasting to work on Linux, you have to be prepared to try four different techniques (with at least one of them allegedly unreliable). Otherwise run “sudo apt-get install xclip” or “sudo apt-get install xsel” (Note: xsel does not always seem to work.) Otherwise on Linux, you will need the gtk or PyQt4 modules installed.” “On Linux, this module makes use of the xclip or xsel commands, which should come with the os. paste () print ( str ( spam ))Īnd this script produces the following: The text to be copied to the clipboard.“Copy to the clipboard” is one of those things that sound easy until you actually try to do it, like “let’s fly to the moon” or “why can’t everyone just get along?”.Įspecially on Linux. ![]() copy ( 'The text to be copied to the clipboard.' ) spam = pyperclip. Here’s what the script looks like now: import pyperclip pyperclip. Of the paste command, so we’ll add a print statement to see. I’m guessing it’s as easy as the ‘paste’ command seen in the previous script. I pasted that into a new Python script, ran it, and was able to paste the contents of the clipboard andīueno! Retrieving Text From the Clipboard The SO answer from above has this code snippet: import pyperclip pyperclip. I did the following: C:\Users\sfrieder>pip3 install pyperclip Hopefully this is something that pip can install for me. The first result seems to have a straightforward answer: use Pyperclip. Install TKinter in order to just get the clipboard. The first result from Googleįorwards me to a big ol’ list of things I can try which seem somewhat involved. With the fact that I want to do it on Windows as opposed to (possibly) Linux. It seems that this is not nearly as straightforward as I thought it might be. This will be done on a Windows 10 PC with Python 3 (3.8.1 specifically). Wouldn’t it be easier if Python could copy the text to the clipboard directly and save me a click? I’m writing a script to generate some text that I would need to copy and paste into a form on a
0 Comments
Leave a Reply. |