472,133 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

Can python access windows clipboard

Can I use python to copy something(like a string) to the clipboard, so
that I can paste it somewhere else. Is there a way to do this?

Thanks very much!

Jun 21 '07 #1
4 18266
Ant
On Jun 21, 9:59 am, MaHL <mhl1...@gmail.comwrote:
Can I use python to copy something(like a string) to the clipboard, so
that I can paste it somewhere else. Is there a way to do this?
The following requires Mark Hammond's win32all package (http://
sourceforge.net/projects/pywin32/):

import win32clipboard, win32con, random

text = "Some text to stick on the clipboard"

win32clipboard.OpenClipboard()
win32clipboard.SetClipboardData(win32con.CF_TEXT, text)
win32clipboard.CloseClipboard()

--
Ant...

http://antroy.blogspot.com/
Jun 21 '07 #2
En Thu, 21 Jun 2007 05:59:06 -0300, MaHL <mh*****@gmail.comescribió:
Can I use python to copy something(like a string) to the clipboard, so
that I can paste it somewhere else. Is there a way to do this?
Yes, using the pywin32 extensions that you can download from Sourceforge

pyfrom win32clipboard import *
pyOpenClipboard()
pyEmptyClipboard()
pySetClipboardText("Hello from Python!")
11272196
pyCloseClipboard()

Ctrl-v: Hello from Python!

--
Gabriel Genellina

Jun 21 '07 #3
MaHL wrote:
Can I use python to copy something(like a string) to the clipboard, so
that I can paste it somewhere else. Is there a way to do this?
If you're using Cygwin Python you can just open /dev/clipboard and work
on that.
--
Michael Hoffman
Jun 21 '07 #4
thanks a lot!

Jun 21 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

52 posts views Thread by Dick Moores | last post: by
11 posts views Thread by Danny J. Lesandrini | last post: by
6 posts views Thread by =?Utf-8?B?TWljaGFlbCAwMw==?= | last post: by
5 posts views Thread by Steve Richter | last post: by
1 post views Thread by Jim Langston | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.