如何记录在pyautogui的提示功能中输入的文本



我正在编写一个程序,我想让用户在pyautogui中以提示函数的形式键入反馈。有什么方法可以记录在这里输入的文本吗;最好是在文本文件中?

他们的文档说,如果用户点击取消,pyautogui.prompt会返回文本输入,或者None会返回。将文本输入写入文件可以这样做:

import pyautogui as py
text = py.prompt(text='Do you like apples?', title='Question', default='YES')
with open('file.txt', 'w') as file:
file.writelines(text)

您可以更容易地将prompt函数的调用保存到变量中,如:

import pyautogui
text = pyautogui.prompt(text='Do you like apples?', title='Question', default='YES')
#now you will have the text entered in the prompt saved in 'text' variable
print(text) 

最新更新