0

I've searched around on stackoverflow and I can't seem to understand how you would copy a string input into the windows clipboard. So what I want to do right now is to take a string in a program in python and place it on the windows 8 clipboard so that I can paste it in other programs, say for example, Google Chrome.

After a cursory search, I found a Tkinter solution, as follows:

from Tkinter import Tk
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append('i can has clipboardz?')
r.destroy()

However I don't understand why it doesn't work. As far as I know, all it does is wipe my current clipboard. Is this OS related?

I've also heard of a win32clipboard module solution for this, but as far as I know, python 2.7 doesn't seem to have a native module for that?

Edasaur
  • 397
  • 1
  • 8
  • 19
  • 1
    Link to source of that Tkinter code: http://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard-on-windows-using-python – leewz Dec 07 '13 at 07:54
  • 1
    Try commenting out the destroy? – leewz Dec 07 '13 at 07:56
  • I tried to do that but nothing happens. When I paste, nothing comes out :( – Edasaur Dec 07 '13 at 08:30
  • Have you tried putting each line, one at a time, into the interpreter and watching what happens with your clipboard? Mine freezes on `r.destroy()` – leewz Dec 08 '13 at 08:08
  • I suspect Windows 8 changed something with the clipboard. What version of Python 2.7 do you have? They might've fixed it. – leewz Dec 08 '13 at 08:09
  • Here's the pywin32 project with the win32clipboard module: http://sourceforge.net/projects/pywin32/files/ – leewz Dec 08 '13 at 08:11
  • I tried line by line and it seems that after clearing the clipboard, when I try pasting, the application freezes. I have python 2.7.6. So the pywin32 project includes a win32clipboard module with which I can edit the clipboard? Also probably pretty important is that I have Windows 8.1 – Edasaur Dec 09 '13 at 06:47

1 Answers1

0
r.destroy()

It destroy the clipboard