0

I'm trying to redirect the powershell-output into a text box in Tkinter. I specifically want the print statements from the command prompt. does anyone know how I can go about this?

I followed this but it won't print to the text box.

my final function looks like this:

def start_script():
os.system('python Script.py')
p = sub.Popen('python ./Script.py', stdout=sub.PIPE, stderr=sub.PIPE)
output, errors = p.communicate()
while True:
    for line in output:
        text.insert(END, line)

It might be because it runs the script and then goes to print out the while true statement but I'm just guessing. Can someone point me in the right direction please?

Community
  • 1
  • 1

1 Answers1

0

There's a similar question here and he built a nice script to have a look at as well. The important line being:

sys.stdout = Std_redirector(text)

To demo, K DawG just uses a simple number generator and the print statement which then outputs to the linked text widget as well as keeping the solution threaded.

Community
  • 1
  • 1
L33tCh
  • 199
  • 4