2012-02-03 178 views
4

python可以清除剪贴板吗?如果是的话......我该怎么做?清除剪贴板?

我需要这个,所以在我的测验计划中,学生无法复制粘贴来自互联网和其他文件的答案。

编辑:进出口使用的WinXP和Python 2.6

+2

¬¬仍然可以写下来,不是吗? – OscarRyz 2012-02-03 02:57:58

+0

类似的问题,相同的基本答案:[我如何从python的(windows)剪贴板中读取文本?](http://stackoverflow.com/questions/101128/how-do-i-read-text-from-the -windows-clipboard-from-python) – kmote 2012-02-03 02:58:05

+0

@OscarRyz他们可以在他们的答案中输入 – Katherina 2012-02-03 03:06:53

回答

10
from ctypes import windll 
if windll.user32.OpenClipboard(None): 
    windll.user32.EmptyClipboard() 
    windll.user32.CloseClipboard() 

无需外部库需要。

+0

嗨,谢谢..这正是我需要的 – Katherina 2012-02-03 08:54:31

1

是的,你可以为你必须使用PyWin32模块,它是Windows ectension一个Python模块。

看看它的EmptyClipboard方法。

The EmptyClipboard function empties the clipboard and frees handles to data in the clipboard. The function then assigns ownership of the clipboard to the window that currently has the clipboard open.

+0

嗨,我下载pyWin32。我该如何导入它?即时通讯使用导入win32clipboard,win32con,随机错误。即时获取此ImportError:DLL加载失败:指定的模块找不到。 – Katherina 2012-02-03 03:07:41

+0

@Katherina:下载PyWin32you的哪个版本。下载一个对应于Python2.6的版本 – RanRag 2012-02-03 04:21:57

+0

是的,我确实下载了python 2.6的安装程序。 idk为什么它会在导入时引起我的错误。无论如何生病尝试再次找到它。 – Katherina 2012-02-03 07:36:54