python - 如何使用python创建复制和粘贴程序
问题描述
如何使用 Python 编写可以在 Windows 中充当复制和粘贴的程序?我用python库做了两个按钮,想在windows环境中复制一个,另一个在粘贴中。谢谢你帮助我。
这是我的代码
import tkinter as tk
import pyautogui as pg
import time
root = tk.Tk()
root.geometry("200x160")
root.resizable(False, False)
is_checked = tk.IntVar()
def alont():
if is_checked.get() == 0:
root.attributes('-topmost', False)
else:
root.attributes('-topmost', True)
text1 = tk.Entry(root, font = ("area", 10), width = 5)
text1.config(insertwidth=1)
text1.place(x=10, y=137)
text1.insert(0, 1)
timer1 = text1.get()
def copy1():
timer1 = text1.get()
tm = int(timer1)
time.sleep(tm)
pg.hotkey('ctrl', 'c')
def paste1():
timer1 = text1.get()
tm = int(timer1)
time.sleep(tm)
pg.hotkey('ctrl', 'v')
btn1 = tk.Button(root, text="Copy", font=("area", 25), height = 1, width = 10)
btn1.config(command=copy1)
btn1.pack()
btn2 = tk.Button(root, text="Paste", font=("area", 25), height = 1, width = 10)
btn2.config(command=paste1)
btn2.pack()
chbutton = tk.Checkbutton(root, text="Always On Top",
font=("area", 12), variable=is_checked)
chbutton.config(command=alont)
chbutton.place(x=60, y=133.5)
root.mainloop()
解决方案
有这方面的现有库。看到这个答案。还有pyperclip。
推荐阅读
- python-3.x - 与 Cassandra 的连接问题 python
- javascript - 如何使用 javascript 或 jquery 创建按钮的动态 tbody onclick
- java - JavaFX如何制作动态相机,如何限制视口可见性
- c++ - 在非实例化模板中使用 static_assert 的正确方法是什么?
- json - 在 play scala 的单元测试中模拟 WsClient
- python - 我无法删除产品
- ios - iOS 订阅 latest_receipt_info
- visual-studio-code - VS Code 无法启动 Bash
- botframework - 创建访问器后无法写入机器人状态属性
- python - ValueError:不支持 ssd_inception_v3。有关与不同版本 TensorFlow 兼容的特征提取器,请参阅 `model_builder.py`