简体   繁体   中英

how to paste text in input field from clipboard using python

i want to paste text in text input field, which is copied from pdf file. i can't use ctrl+v to paste. so is there any way to do so with python or any other?

from tkinter import Tk
root = Tk()
root.withdraw()
result = root.clipboard_get()
print(result)

this is the code that fetch data from clipboard. it prints the copied text. but when i run the script with shortcut key it does not paste the text to input field.

i also tried

import pyautogui
x, y = pyautogui.position()
pyautogui.click(x, y)

to get focus back where i want to paste text.

Add this after pyautogui.click(x, y)

pyautogui.typewrite(result)

so full code will be as follows

import pyautogui
from tkinter import Tk
root = Tk()
root.withdraw()
result = root.clipboard_get()

x, y = pyautogui.position()
pyautogui.click(x, y)
pyautogui.typewrite(result)
import pyperclip
result = pyperclip.paste()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM