擅长:python、mysql、java
<p>您需要将<code>pyperclip.paste()</code>传递到为条目或文本小部件插入放置字符串的同一位置。</p>
<p>看看这个示例代码。</p>
<p>有一个按钮可以复制输入字段中的内容,还有一个按钮可以粘贴到输入字段。</p>
<pre><code>import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk()
some_entry = tk.Entry(root)
some_entry.pack()
def update_btn():
global some_entry
pyperclip.copy(some_entry.get())
def update_btn_2():
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert(tk.END, pyperclip.paste())
btn = ttk.Button(root, text="Copy to clipboard", command = update_btn)
btn.pack()
btn2 = ttk.Button(root, text="Paste current clipboard", command = update_btn_2)
btn2.pack()
root.mainloop()
</code></pre>
<p>或者,您可以只执行<kbd>Ctrl</kbd>+<kbd>V</kbd>:D</p>