set_println_stream()#

Customize where the output of println() goes.

Examples#

 1import ipywidgets as widgets
 2from IPython.display import display
 3
 4
 5class WidgetPrintlnStream:
 6
 7    def init(self):
 8        self.out = widgets.Output(layout=dict(
 9            max_height='200px', overflow='auto'))
10        display(self.out)
11
12    def print(self, text, end='\n', stderr=False):
13        if stderr:
14            self.out.append_stderr(text + end)
15        else:
16            self.out.append_stdout(text + end)
17
18
19py5.set_println_stream(WidgetPrintlnStream())

Description#

Customize where the output of println() goes.

When running a Sketch asynchronously through Jupyter Notebook, any print statements using Python’s builtin function will always appear in the output of the currently active cell. This will rarely be desirable, as the active cell will keep changing as the user executes code elsewhere in the notebook. The println() method was created to provide users with print functionality in a Sketch without having to cope with output moving from one cell to the next. Use set_println_stream to change how the output is handled. The println_stream object must provide init() and print() methods, as shown in the example. The example demonstrates how to configure py5 to output text to an IPython Widget.

Syntax#

set_println_stream(println_stream: Any) -> None

Parameters#

  • println_stream: Any - println stream object to be used by println method

Updated on September 11, 2021 16:51:34pm UTC