Redirect command line results to a tkinter GUI

You could create a script wrapper that runs your command line program as a sub process, then add the output to something like a text widget.

from tkinter import *
import subprocess as sub
p = sub.Popen('./script',stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()

root = Tk()
text = Text(root)
text.pack()
text.insert(END, output)
root.mainloop()

where script is your program. You can obviously print the errors in a different colour, or something like that.

Leave a Comment