su2187
su2187

Reputation: 171

How do I record text entered in the prompt function of pyautogui?

I'm writing a program, and I want to make users type feedback in the form of a prompt function in pyautogui. Is there any way I can record the text entered here; preferably in a text file?

Upvotes: 1

Views: 961

Answers (2)

Pushkar Saini
Pushkar Saini

Reputation: 1

More easily you can just save the calling of prompt function to a variable,like:

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) 

Upvotes: 0

Andrew Stone
Andrew Stone

Reputation: 1090

Their docs say that pyautogui.prompt returns the text input or None if users hit cancel. Writing the text input to a file can be done like this:

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)

Upvotes: 1

Related Questions