26 Mar 2009

Python Tips之 - 操作Windows剪贴板

Python学习笔记: 操作Windows剪贴板

This article is mainly about using Windows Clipboard

22/11/2009 updata: 另外一篇关于剪贴板的帖子,看这里.

必须安装PyWin32,可惜,我的PyWin在安装ActivePython失败之后,一直弹出vs Debugging,出错不能运行.谁知道怎么解决吗?无奈,只好继续IDLE了.习惯就好.(PyWin32下载地址: http://sourceforge.net/projects/pywin32/)

In order to use this code, you have to install PyWin32 from the source forge:
http://sourceforge.net/projects/pywin32/
Unfortunately, it didn't work for me. Maybe because I have been faild to install ActivePython.
The VS Debugging dialog would appear if I tried to run it. Can anybody help? Please leave a comment.

安装好之后,就可以操作剪贴板了,代码如下:
You can use clipboard as soon as you install the pywin32 modules as following:



>>> import win32clipboard, win32con
>>> txt = 'Some text'
>>> win32clipboard.OpenClipboard()
>>> win32clipboard.EmptyClipboard()
>>> win32clipboard.SetClipboardData(win32con.CF_TEXT,txt)
>>> print win32clipboard.GetClipboardData()
Some text
>>> win32clipboard.CloseClipboard()
>>> 

No comments :

Post a Comment