python写入并获取剪切板内容的实例
作者:泛舟流年 时间:2023-08-03 10:44:04
写桌面程序或有些特殊操作的,经常需要访问剪切板。python有专用的模块,可以很方便简单的操作剪切板
如下:
#coding:utf-8
import win32clipboard as w
import win32con
#获取剪切板内容
def gettext():
w.OpenClipboard()
t = w.GetClipboardData(win32con.CF_TEXT)
w.CloseClipboard()
return t
#写入剪切板内容
def settext(aString):
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_TEXT, aString)
w.CloseClipboard()
a = "hello python"
settext(a)
print gettext()
上述小程序运行后会打印出 hello python 字符。
可以尝试注销写入剪切板代码,然后使用 Ctrl+c 来复制一段字符,然后运行程序。
或者注销获取剪切板代码,运行程序后再使用 Ctrl+v 来粘贴。
可以更直观的看到结果
来源:https://blog.csdn.net/qq_35885203/article/details/70154294
标签:python,剪切板
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Opencv+Python实现图像运动模糊和高斯模糊的示例
2022-08-06 12:25:19
![](https://img.aspxhome.com/file/2023/9/66349_0s.jpg)
Sql Server中REPLACE函数的使用
2024-01-25 10:48:51
vue中使用props传值的方法
2024-05-03 15:10:50
详解如何在微信小程序开发中正确的使用vant ui组件
2024-05-25 15:18:33
![](https://img.aspxhome.com/file/2023/5/123715_0s.png)
Python单例模式实例详解
2021-06-26 03:06:17
python 日志 logging模块详细解析
2022-06-12 15:11:51
解决python问题 Traceback (most recent call last)
2021-10-31 06:17:49
![](https://img.aspxhome.com/file/2023/1/114631_0s.jpg)
基于Python编写一个简单的端口扫描器
2021-09-19 09:21:22
![](https://img.aspxhome.com/file/2023/4/110454_0s.jpg)
解决PyCharm 中写 Turtle代码没提示以及标黄的问题
2023-05-12 09:08:30
![](https://img.aspxhome.com/file/2023/0/75950_0s.jpg)
python计算最小优先级队列代码分享
2022-12-05 03:26:50
Go语言自带测试库testing使用教程
2024-04-26 17:31:49
sql2000各个版本区别总结第1/3页
2024-01-15 10:09:42
使用symfony命令创建项目的方法
2023-11-15 10:07:45
详解python的变量
2021-01-26 20:44:20
![](https://img.aspxhome.com/file/2023/1/124771_0s.png)
Eclipse + Python 的安装与配置流程
2021-07-25 06:34:18
Python中如何引入第三方模块
2023-08-27 08:34:48
Get方法和Post方法的区别深入理解
2023-12-09 11:42:18
Python绘制词云图之可视化神器pyecharts的方法
2022-12-08 14:38:44
![](https://img.aspxhome.com/file/2023/7/95417_0s.png)
MySQL的一些安全注意点
2008-12-24 16:29:00
python OpenCV 图像通道数判断
2023-10-15 18:21:22