I have a Python GUI written with tkinter
which calls a second function upon a button press. This function then waits for an input, using raw_input()
and then acts upon the result. i.e. the function is of the format:
DO THINGS
a = raw_input('Enter value: ')
if int(a) == 0:
do this
elif int(a) == 1:
do something else
From my GUI, I want to send the value (0
or 1
or more options), such that the function continues to execute as I ask. I will do this with a button press in tkinter
, but that's not important, the key is how to send this value to the command line.
I have looked at subprocess.Popen
and subprocess.communicate
:
How to make python script press 'enter' when prompted on Shell
and Pexpect
:
python pexpect sendcontrol key characters
However, I'm a relative novice with Python and Linux, and can't get these to work - perhaps they are correct but I just need a bit more of a specific answer for my work. I feel like this question should be very easy to solve, but I just can't find how to do it. I'd also rather work with built-in modules, so if it can be done without Pexpect
that would be great - I think I'm right in saying this doesn't come as part of the initial Python installation.