如何记录pyautogui的提示功能中输入的文字?

问题描述

我正在写一个程序,我想让用户pyautogui中以提示功能的形式输入反馈。有什么办法可以记录在此处输入的文本;最好在文本文件中?

解决方法

他们的 docspyautogui.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)