detect incoming output to be displayed the non-gui script would not be blocked by mainloop call for examplethe gui could be spawned by the non-gui script as separate programwhere user interaction results can be communicated from the spawned gui to the script using pipessocketsfilesor other ipc mechanisms we met in the advantage to this approach is that it provides separation of gui and non-gui code--the nongui script would have to be modified only to spawn and wait for user results to appear from the separate gui programbut could otherwise be used as is moreoverthe nongui script would not be blocked while an in-process mainloop call runs (only the gui process would run mainloop)and the gui program could persist after the point at which user inputs are required by the scriptleading to fewer pop-up windows in other scenariosthe gui may spawn the non-gui script insteadand listen for its feedback on an ipc device connected to the script' output stream in even more complex arrangementsthe gui and non-gui script may converse back and forth over bidirectional connections examples - - and - provide simple example of these techniques in actiona non-gui script sending output to gui they represent non-gui and gui programs that communicate over sockets--the ipc and networking device we met briefly in and will explore in depth in the next part of the book the important point to notice as we study these files is the way the programs are linkedwhen the non-gui script prints to its standard outputthe printed text is sent over socket connection to the gui program other than the import and call to the socket redirection codethe non-gui program knows nothing at all about guis or socketsand the gui program knows nothing about the program whose output it displays because this model does not require existing scripts to be entirely rewritten to support guiit is ideal for scripts that otherwise run on the world of shells and command lines in terms of codewe first need some ipc linkage in between the script and the gui example - encapsulates the client-side socket connection used by non-gui code for reuse as isit' partial work in progress (notice the ellipses operator in its last few functions--python' notion of "to be decided,and equivalent to pass in this contextbecause sockets are covered in full in we'll defer other stream redirection modes until thenwhen we'll also flesh out the rest of this module the version of this module here implements just the client-side connection of the standard output stream to socket--perfect for gui that wants to intercept non-gui script' printed text example - pp \gui\tools\socket_stream_redirect py ""[partialtools for connecting streams of non-gui programs to sockets that gui (or othercan use to interact with the non-gui programsee and pp \sockets\internet for more complete treatment "" gui coding techniques