The code below implements a GUI window for output display, such as might be used as a console to display status messages or other information from a running program. It is implemented using a threaded Tkinter Toplevel widget, and is designed to be used in a non-GUI command-line program. The display that it produces looks like this:
The Python code for this GUI console is:
Because it runs in its own thread, this console can be used to display information produced by the main program or even several other separate processes.
The 'write()' method of the ConsoleUI object will write the given text at the end of the console display. A status message can also be written, separately from the stream of text that is written in the main part of the window. The console window can be closed directly from the program with the 'deactivate()' method, or the program can pause until the user closes the window by using the 'wait_for_user_quit()' method.
Other Tkinter widgets should not be activated in other threads while this GUI console window is open.