I want the output of a Python script in a Tkinter text widget instead of in the command line. I have this script from https://stackoverflow.com/a/665598/3524043:
from Tkinter import *
import subprocess as sub
p = sub.Popen('./Scripts/Speedtest.py',stdout=sub.PIPE,stderr=sub.PIPE, shell=True)
output, errors = p.communicate()
root = Tk()
text = Text(root)
text.pack()
text.insert(END, output)
root.mainloop()
I've added shell=true
at the subprocess, cause I had a OSError: [Errno 13] Permission denied
.
When I run the program there's only an empty text widget.
Edited with a better solution:
Import the script and call the objects
from Tkinter import *
from Speedtest import ping_speed, download_speed, upload_speed
root = Tk()
text = Text(root)
text.insert(INSERT, ping_speed)
text.insert(END, download_speed)
text.pack()
mainloop()