title: Platform independent tool to copy text to clipboard
body: <p>I am trying to write a function that <em>copies a string parameter to the clipboard</em>. I intend to use this in a Python script that I've been working on. This is what I have so far (found most this snippet on another stack overflow post):</p>
  
  <pre><code>from tkinter import Tk
  
      def copy_to_clipboard(text):
          text = str(text)
          r = Tk()
          r.withdraw()
          r.clipboard_clear()
          r.clipboard_append(text)
          r.destroy()
  </code></pre>
  
  <p>My problem is that when the script stops, the copied text is no longer on the clipboard. </p>
  
  <p>Is there any possible alternative or fix to this? </p>
  
  <p>Is there a good platform independent solution to my problem? Or will I have to check for what OS the user is on and proceed from there?</p>