div*_*ngh 5 python tkinter python-3.x pyperclip tkinter-entry
如果我执行这段代码,它工作得很好。但是,如果我使用键盘(Ctrl+ C)复制某些内容,那么如何将剪贴板上的文本粘贴到Python中的任何输入框或文本框中?
import pyperclip
pyperclip.copy('The text to be copied to the clipboard.')
spam = pyperclip.paste()
Run Code Online (Sandbox Code Playgroud)
您需要删除以下行,因为它会覆盖您使用键盘复制的内容。
pyperclip.copy('The text to be copied to the clipboard.')
Run Code Online (Sandbox Code Playgroud)
例如,我复制了您问题的标题,下面是我将其粘贴到 python shell 中的方法:
>>> import pyperclip
>>> pyperclip.paste()
'How do I paste the copied text from keyboard in python\n\n'
>>>
Run Code Online (Sandbox Code Playgroud)