python 复制文件到剪贴板,访问通过python复制到剪贴板的文本

So I want to be able to use a python script to copy the contents of a folder and then be able to paste those contents to a location of my choosing i.e. text file, browser, etc... I came across this solution for copying text to the clipboard, but when i implement this solution I am not able to paste anything. I am using python 3.4. Below is code i am using:

import os

import tkinter as tk

import tkinter.filedialog

r = tk.Tk()

r.withdraw()

photo_path= tkinter.filedialog.askdirectory(title='Which folder would you like to copy the contents from?', initialdir='/')

# Get list of filenames in current directory

file_list=[]

for filename in os.listdir(photo_path):

if os.path.splitext(filename)[1]=='.JPG':

file_list.append(os.path.splitext(filename)[0])

else: pass

file_search='code:('+' OR '.join(file_list)+')'

r.clipboard_clear()

r.clipboard_append(file_search)

r.destroy()

解决方案

If you don't use the clipboard content before your script ends, it is discarded. Keep it running until you no longer need the clipboard content. The following program will keep '1234' in the clipboard for 10 seconds. If you don't paste it within that time, it is lost. If you do paste it within that time, it will remain in the clipboard even after the program ends.

import tkinter as tk

r = tk.Tk()

r.withdraw()

r.clipboard_clear()

r.clipboard_append('1234')

r.after(10000, lambda: r.destroy())

r.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值