standard streams to be unbufferedso we get printed text immediately as it is producedinstead of waiting for the spawned program to completely finish we talked about this option in when discussing deadlocks and pipes recall that print writes to sys stdoutwhich is normally buffered when connected to pipe this way if we don' use the - flag here and the spawned program doesn' manually call sys stdout flushwe won' see any output in the gui until the spawned program exits or until its buffers fill up if the spawned program is perpetual loop that does not exitwe may be waiting long time for output to appear on the pipeand hencein the gui this approach makes the non-gui code in example - much simplerit just writes to standard output as usualand it need not be concerned with creating socket interface compare this with its socket-based equivalent in example - --the loop is the samebut we don' need to connect to sockets first (the spawning parent reads the normal output stream)and don' need to manually flush output as it' produced (the - flag in the spawning parent prevents bufferingexample - pp \gui\tools\pipe-nongui py non-gui sideproceed normallyno need for special code import time while trueprint(time asctime()time sleep( non-gui code sends to gui process no need to flush here start the gui script in example - it launches the non-gui program automaticallyreads its output as it is createdand produces the window in figure - --it' similar to the socket-based example' result in figure - but displays the str text strings we get from reading pipesnot the byte strings of sockets this worksbut the gui is odd--we never call mainloop ourselvesand we get default empty top-level window in factit apparently works at all only because the tkinter update call issued within the redirect function enters the tk event loop momentarily to process pending events to do betterexample - creates an enclosing gui and kicks off an event loop manually by the time the shell command is spawnedwhen runit produces the same output window (figure - example - pp \gui\tools\pipe-gui py gui reader sidelike pipes-gui but make root window and mainloop explicit from tkinter import from pp gui tools guistreams import redirectedguishellcmd def launch()redirectedguishellcmd('python - pipe-nongui py'more ways to add guis to non-gui code