Redirecting the command-line output to Tkinter

You may occasionally need to redirect the output of a command line to a GUI such as Tkinter. The ability to pass outputs from the command line to Tkinter opens a large pool of possibilities for using the inherent powers of the shell on Unix and Linux operating systems and the Windows shell on a Windows machine.

We will demonstrate this by using the subprocess Python module, which lets us spawn new processes, connect to the input, output, and error pipes of this new process, and obtain the return codes from the programs.

A detailed discussion on the subprocess module can be found at https://docs.python.org/3/library/subprocess.html.

We will use the Popen class from the subprocess module to create ...

Get Tkinter GUI Application Development Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.